Set mesh orientation during physics simulation

In this playground https://playground.babylonjs.com/#93HGU7#88 I have a simulation going on, and it has a heading property that says the orientation of the object and I want to use this informantion to set the rotation of the mesh during the simulation.
I’ve tried to update using mesh.rotation.y without success and with math.rotate function but with this one it keep spinning instead of just updating the orientation.

Thanks :slight_smile:

cc @Cedric our physix guru

Once a physics impostor is used, the mesh quaternion is used instead of euler angles.
To get the mesh aligned on linear velocity direction, compute the atan from the velocity and use that angle to compute a quaternion.

Check lines 736-738

Don’t forget to add a check on linear velocity length or it will try to normalize a 0-lengthed vector.

4 Likes

Thank you @Cedric :smiley:

1 Like