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 https://www.babylonjs-playground.com/#JI94L6#5

Hiya RW, welcome to the forum.

https://www.babylonjs-playground.com/#JI94L6#6

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.

1 Like

Update: OMG… check this out:

https://doc.babylonjs.com/api/classes/babylon.mesh#reintegraterotationintorotationquaternion

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

And watch what it does…

https://www.babylonjs-playground.com/#JI94L6#7

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:

3 Likes

I know this is a long shot but I ran into this answer on my search to solve a similar problem, I have a forum post already made here and could really use the help. Thanks! I’ve tried using the rotate function and it works on the first click but not always after that,