How to prevent dynamic bodies from pushing each other when using havok?

How to prevent dynamic bodies from pushing each other when using havok?

CC @Cedric

One way would be to use membership and collision masks: put all the dynamic bodies in the same group and then set them to collide with everything but themselves:


This question needs a bit more context :slight_smile:
Otherwise, what @CrashMaster said !

1 Like

no i want them to collide with each other

Here is a video:

I want them to collide but won’t be able to push each other.

1 Like

You can set the velocity to 0 when you detect the collision between the 2 objects

I did but it only slowed down the movemet

can you share a repro in the playground? It will be harder to go further without playing with it a little bit :wink:

A playground would be handy. But if I recall correctly I think set the body to ANIMATED not DYNAMIC.

do you really need physics for that? I mean it’s like setting 1 position based on position + radius of the opponent.

sure, here is a simple one
Stop physics bodies from pushing each other | Babylon.js Playground (

they won’t interact with each other this way

I didn’t get it. could you explain a bit more, please?

There you go:

As I suggested, setting the velocity of both bodies to 0 on collision does the trick :wink:

I had that in mind:

check lines 38 and 42.

1 Like

That won’t work if the applies any kind of inputs changing his velocity.
The physics engine will still do velocity and position correction iterations, resulting in one body pushing the other.

Without testing it, I think a possible solution might be something along these lines:
Each player has two physics bodies. A dynamic one and a kinematic one. These two bodies are filtered so they don’t collide with each other. When applying inputs, you move your dynamic body, and use the difference in position between the current frame and the previous one to set the velocity of the kinematic body. This gives a one-frame lag on the kinematic body, but this is still preferable to blindly setting its velocity to that of the dynamic body, as this will possibly push the kinematic body into the kinematic body of another player, causing undesirable movement as well

The dynamic body of player A will stop dead when hitting the kinematic body of player B. And vice versa


Thank u for your solution. here’s what I did:

  1. attach a dynamic rigid body to the root mesh.
  2. add a new box and add it to the root mesh children list
  3. attach an animated rigid body to the newly added box and set disablePreStep to false
  4. use any observable like onBeforeRender to set the position of the new box to (0, 0, 0)