godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.83k stars 21.13k forks source link

RigidBody2D tunnels CollisionShape2D and bounces back with even greater momentum #36294

Open udit opened 4 years ago

udit commented 4 years ago

Godot version: 3.2

OS/device including version: Windows 10

Issue description: When a RigidBody2D with very small mass (e.g. 0.1) is connected with a PinJoint2D to another RigidBody2D with a larger mass like (e.g. 100), the heavier body pushes the smaller mass through the CollisionShape2D of another object that it is collides with and bounces back with even greater momentum. This effect diminishes as you keep increasing the mass of the lighter body.

RigidBody2D should not pass through CollisionShape2D of another object and should not bounce back with a greater momentum than before collision.

Minimal reproduction project: CollisionBug.zip

Calinou commented 4 years ago

The tunneling issue is being tracked in #9071.

udit commented 4 years ago

I skimmed through #9071 and I may be wrong but it seems the issue here is a bit different. The RigidBody2D doesn't completely miss the collision. In fact, it does detect the collision but partially overlaps with the CollisionShape2D of another body and then bounces back as seen in the above GIF (or in the minimal reproduction project).

If I increase the mass of the smaller RigidBody2D to a significantly bigger value like 10, then it doesn't overlap with the collision even though it would be falling down at the same speed as before.

Xrayez commented 3 years ago

The RigidBody2D doesn't completely miss the collision. In fact, it does detect the collision but partially overlaps with the CollisionShape2D of another body and then bounces back

Yeah, but due to static nature of collision detection, it can only check if those shapes are colliding at the current frame. Since simulation is proceeded with fixed physics step, in most cases penetration will occur, so it needs to be corrected. And this correction may introduce momentum to the system, I suppose. Therefore, #9071 could completely prevent penetration from occurring in the first place.

See also my hypothesis at https://github.com/godotengine/godot/issues/52550#issuecomment-925748860.

By the way, setting softness of the pin joint to 0.1 helps those bodies to stay grounded.