How to get the correct new direction/rotation of a mesh?


I am currently coding a game in babylonjs and I need to send the direction or the rotation of some meshes, but I can’t seem to make it work. Despite me clearly changing the rotation of the object, calling rotation or getDirection on that object doesn’t output the expected results at all. Am I misunderstanding something?

Here’s a short playground of my issue:

Thanks a lot for reading me.

Hey there, welcome to the forum. :slight_smile:

So getDirection relies on the mesh’s world matrix, which you can force to be updated by calling computeWorldMatrix(true) on the mesh. Then getDirection will return the new direction.

For the second part in the PG, the rotate function performs the requested rotation using the rotationQuaternion property, so it converts the rotation vector to a quaternion and resets the vector to 0, 0, 0. However you can call toEulerAngles() on the rotationQuaternion to get the corresponding euler angles.

Here’s the PG updated to do these things.


Thanks a lot for your help! :smile: