matter-js icon indicating copy to clipboard operation
matter-js copied to clipboard

Infinite mass body moves on collision with a light body

Open akantic opened this issue 4 years ago • 5 comments

Hi, I am having trouble in a situation where a small body is capable of pushing a large (and much heavier) body on collision.

I have recreated and simplified my problem here. Here, even an object with infinite mass is moved on impact with a light body.

akantic avatar Feb 23 '20 16:02 akantic

Why does the body have infinite mass? Could you use a static body instead? One thing to note is that there will likely be instability between two bodies that have large differences in mass.

liabru avatar Mar 06 '20 16:03 liabru

In my case, the larger mass body is a player and the lighter one is a projectile. Player needs to move, so I can not make it static. I don't want player's position to be affected by colliding with a projectile. I destroy projectiles on collision, but each hit moves it by a bit despite making projectiles featherweight.

The behavior is identical to the sandbox link I provided. I started with realistic numbers for density/weight, but realized that this does not change even by using extreme and unreliable values, like infinity.

akantic avatar Mar 06 '20 19:03 akantic

@liabru I isolated my problem to collision position resolver, which is not taking body mass into account in any of the calculations, unlike collision velocity resolver.

akantic avatar Mar 07 '20 16:03 akantic

That's right the position solver doesn't provide any physical response, it just reduces the overlap evenly between bodies. Then the velocity solver finds the response.

Are you sure that's part of the problem? Do you mean that the position solver should only move the projectile?

liabru avatar Mar 07 '20 17:03 liabru

This behavior seems counter-intuitive to me. I do not expect a heavy object to be affected by something much lighter in any way. In my case, many projectiles collide with a player constantly and it causes a lot of unwanted movement for the player (a heavy object).

Something like this comes to mind, but I am not sure if this would break other stuff. Also would be great to hear if there is a workaround for this.

akantic avatar Mar 07 '20 19:03 akantic