Unnatural swerve after applying an impulse

Hello once again!

I am working on a game which main mechanic is pushing cylindrical pawns into a hole located in the middle of a game board. I am using CannonJS physics engine and I encountered a problem.

I noticed that when I slide my cylinders, they tend to get an unnatural swerve just before stopping. It happens every time I apply an impulse that is stronger on one axis (x or z). I suspect this is caused by the friction stopping the cylinder on one axis faster than on the other.

I want to apply impulses in a way that would allow me to move my pawns in straight line in any direction. Is there a way for me to achieve that with CannonJS? Choosing different engine is not really an option for me due to other, more significant problems.

I prepared a playground example to demonstrate my problem: Babylon.js Playground

Adding @RaananW our physics expert

Hey!

First, when you have the time (and want to) I will be happy to hear what problems you have with the other physics engines. but this is a different subject. I like cannon too :slight_smile:

Just to be sure we are talking about the same thing - are you referring to the fact that the pawn (i will call it pawn if it’s ok) doesn’t move straight, but moves a bit to the left when moving towards the center?

Have you tried using a mesh impostor instead of the collection of box impostors? As you wrote, it feels like this is an issue of too many friction points with several meshes at once. I haven’t debugged it yet, i just want to make sure we are at the same page.

Thank you for your reply!

Yes, I expect the pawn to move straight into the center of the game board.

Yes, I’ve tried using a mesh impostor but it did not work as expected either. You can check out my previous question to know exactly what went wrong and how I came up with current approach: How to efficiently implement cylindric hole physics?

Hi,

yep - too many collisions at the middle. Here is the bounding boxes of all physics colliders, with only 10 boxes added - image

What you can do is detect which boxes SHOULD collide against it on each frame, and enable/disable them. This is not an optimal solution (and can be optimized, i’m sure). Another solution is to force the object’s trajectory on each from (check its linear velocity on each frame).

Anyhow, leaving all of those colliders on will cause unexpected friction movement.