Node vehicle as root of vehicle;
car model (spatial) load and attached to vehicle node.
I used some Node (as seats) to determine positions of seats and in constructor of vehicle class I initialized their positions by setLocalTranslation().
when a character attached to seat (get on vehicle) have correct position if vehicle rotation is zero.
if vehicle have rotation then all seats moved some unit in attaching character spatial to it.
Hello @yn97, can you provide us with a before and after screenshot of the issue, I am having trouble visualizing the problem, but I think I understand what you are saying.
Are you changing the position of the nodes after rotating?
Are the character nodes attached to the vehicle node? It looks like the vehicle node was rotated, but the other nodes are not attached to it, thus did not get rotated.
Hmm, I see that the characters have rotated along their center axis, but the vehicle itself is not rotated along its center axis? Without seeing the code this will be hard to trouble shoot.
There is a trick to this. I remember this issue when I was adding joints to a car. When you add a node it acts as if the car has not rotated. I can’t remember if it was worldToLocal(Vector3f) or something, but there is a method that calculates this for you. If I remember i’ll post it.
it was not a rotation problem.
I found that when a node have parent(root Node) attached to another node it keeps last local Translation.
i don’t know it is a bug or feature? and how can I fix it?
Spatials remembering their local translation is a feature. When parenting in the way you are describing be sure to set the new local translation you wish to use at the time you assign the new parent. Setting local translation before or after giving the spatial a parent is very common practice and is something you should plan to utilize given situations where you may want to “prep” a group of spatials before adding them to a scene.
That being said, if, for example, you game was structured with the physics engine on the server, you’d effectively be setting the world position of the riders every frame on the client. Not much difference.
But if your spatials are you game objects (as I suspect they are) then it is a little hacky and may lead to some weird timing bugs down the road as you forget which thing is updated when.
Respectfully, it may also be a learning opportunity to at least work through getting the attachment working.
This whole thread is a sign that there is some (maybe small?) confusion about how scene graphs are supposed to work. Working through the issue may teach some valuable skills for the next problem.
Being able to convert to and from local reference reference frames is a very helpful thing to be able to do in general.