Prevent mesh rotation/repositioning on specific axes

Some suggestions/things you should try:
Mixing forces/impulses and settting body position and orientation at the same time is a bad idea. Physics engine internal states get mad after a while and you’ll get weird results after a while. It can become incontrollable and I think it’s the case here.
You should try ammojs. It’s more supported than cannon and overall, I think the resolution quality is much better. And you’ll get more controls.
Do not try to constain a body position by setting a new position. Instead, favor changing its angular or linear velocity. Like this:

var vel = player.physicsImpostor.getLinearVelocity();
player.physicsImpostor.setLinearVelocity(new BABYLON.Vector3(vel.x, vel.y, 0));

For angular velocity, set all angular speed to 0 so the mesh will not rotate. Ammojs provides

setAngularFactor

that you can call on ammojs rigid body.Or a more ‘manual’ way is to setAngularVelocity to (0,0,0) each frame.

4 Likes