Rotate mesh with PhysicsImpostor

I can’t rotate a mesh with PhysicsImpostor. my gall is the reset a mesh position and orientation after applying force.

I can change the position of the mesh but not the rotation.

I tried to set the mass to zero, sleep, dispose the imposter set the imposter to null, nothing seems to work. see demo here

Hiya RW, welcome to the forum.

Check out line 54… a different kind of “rotate”.

Some call it… rotationQuaternion -rotate… or just ‘quat-rot’. hehe

At certain times/purposes, BabylonJS mesh use mesh.rotationQuaternion instead of mesh.rotation… to store the rotational values.

Physics engines LOVE quaternion-based rotation, and dislike Euler (like .rotation). SO… yep… when the physics engines are involved, you can be sure that box.rotationQuaternion is in-use.

I HOPE I’m using the rotate() func correctly in line 54. You might want to do some research on it. If you know your “quats”, you can go right in and poke it with values, or use one of MANY helper tools on BabylonJS Quaternion-class objects (there’s even a fromEulerVector).

box.rotationQuaternion is a quaternion-class object, of course.

Quaternions are not for children. :slight_smile: Sometimes they require a bit of web study, and a bit of knowledge about matrix transformations might help. A quaternion is a 4-value data-type, and is used for rotations (including real spacecraft) where a phenomenon called “gimbal lock” is to be avoided. Exciting story, eh? (snore) :slight_smile:

Some have said it like this: THREE quat values are for aiming an arrow in 3d space, and the 4th quat value… is the amount of mesh rotation AROUND that arrow’s shaft. The “order” of the values in a quat… are important, too.

Update: OMG… check this out:

“.reIntegrateRotationIntoRotationQuaternion” It’s GOTTA BE the longest property name on mesh class objects!

And watch what it does…

I set it true in line 17.

THEN… down in lines 57/58, I can disable line 57, and use simple Euler rotation line 58 ONLY, yet the crate always resets to rotated condition, like it is supposed to. YAY.

Line 17… tells BabylonJS engine… to ALWAYS automatically “sum” user-value in .rotation… with current values of .rotationQuaternion! How handy, huh?

These core-coders 'round here are just geniuses. Automatically sum our Euler-rot with our Quat-rot… on user-choice of scene mesh. SO GOOD! Let’s pour whiskey. :slight_smile: