Simple way to freeze rotation

I was searching for a proper and simple way to freeze rotation just like Unity does and after nothing that I tried worked I ended up with that @Cedric solution, but the thing is that we do not have anything like it on the docs, at least I didn’t found it.

Since this is something really important for games in general and it is somewhat hard to find it could be added to the main API of the babylonjs!

I would like to know your thoughts about it also btw, this is motivate because if you add a simple cube on a plane, add a phisical “jump” to that cube, if you jump a couple of times the cube starts to rotate cause of its colision on the floor and I think this isnt the expected behavior of the most of the cases.

It’ll also be good to allow us to touch it withing typescript since we got the error that we should not access private properties.

What I tried:

  • Add I higher damping on the Mesh creation
  • setAngularVelocity to 0
  • setLinearVelocity to 0

What worked:

  • The method suggested by @Cedric on this post
  • Add the setLinearVelocity to a zero vector on each call of onBeforeRenderObservable

Did you try to set the rotationQuaternion value each frame?

No I didn’t, but lmk if I’m wrong, that kind of approach that re-set something each frame isn’t like a work around instead of a proper solution? I mean, it sounds way better to me to kind of make the object hard to rotate other than re-set its rotation every frame.

Like, reset the rotation every frame using quaternions or linearVelocity, to a dummy in this subject like me, seems like almost the same thing, just changing the way we reset it. It isnt? :thinking:

1 Like

Hey @Cedric wanted to know if that makes sense of if I’m wrong about reset the values on each frame!

Wanted to understand your thought about it!

Have you seen this thread ? Ammo setDamping cannot prevent rotation of impostor - #2 by gbz

I forgot about this feature: Freezing rotation for Physics imposter (similar to unity) - #4 by Cedric

1 Like

Hey @Cedric I’m really sorry for the late answer, I completelly miss that ;-;

Just read it here and the tests worked pretty fine, also not throwing a error on typescript, Im just curious now of what is the difference between setAngularFactor on physicsBody and physicsImpostor? Do you know why it behave differently? :thinking:

I think it ends up calling the same method. let me know if it’s not the case.