matter-js
matter-js copied to clipboard
Infinite mass body moves on collision with a light body
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.
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.
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.
@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.
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?
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.