Hello everybody,
I have some problems with setting the local translation of objects.
Following situation:
I have some kind of portals on my world map. Two portals are linked together and if the player steps on one portal, he should be teleported to the other which is linked to it. Well, emphasis is "should" At the moment the player ends up at any point of the map (or outside of it), but not the linked portal.
I implemented it in a way like this:
Every portal has stored the local translation of its targeted portal. If the player uses the portal, his local translation will be set to the target's local translation (with .setLocalTranslation()).
I printed out the stored Vector for translation in the starting portal, the local translation of the targeted portal and the local translation of the player after teleporting - they all have the same value. So I do not understand why he ends up everywhere but not at the target.
What could be the reason and how can I make it better?
Maybe this is only a stupid beginner's problem and I simply did not understand how .setLocalTranslation() works (Okay I'm quite sure I did not understand ).
You need to compare world translation rather than local translation when checking if things are in the same place.
Local translation is just the offset from this object's parent, which could be anything.
Are all the portals, and the player, attached directly to the same node?
If so, make sure that everything has been updated.
awwww
This problem took me hours and the solution is that simple :-o
You are right, my player consists of two nodes, where the inner node holds a DynamicPhysics model and the outer node is attached to the scene. Because the Physics model needs special handling for setting its position while the game runs (clear dynamics and so on), I moved the model instead of the parent node.
But when I initialized the game, I set the parent's position.
All to do was setting the model's position and do nothing to the parent.
Now I only have to take care about the endless loop of teleporting
Thank you for your answer.