godotengine / godot

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

RigidBody gains momentum with each collision when bounce = 1 (both 2D and 3D, Bullet and GodotPhysics) #52550

Closed udit closed 2 years ago

udit commented 3 years ago

Godot version

3.3.3.stable

System information

Windows 10

Issue description

Current behaviour: When RigidBody2D's bounce is set to 1, it keeps gaining more speed every time it bounces off a StaticBody2D, when angular and linear damp are set to 0.

Expected behaviour: RigidBody2D should conserve momentum and bounce back with same speed.

Steps to reproduce

Run the main scene in below minimal reproduction to observe that RigidBody2D keeps gaining more speed with each bounce. output

Minimal reproduction project

RigidBody2DTest.zip

Calinou commented 3 years ago

Out of curiosity, can you (or anyone else) reproduce this issue in 3D with Bullet and GodotPhysics?

udit commented 3 years ago

Did a test with RigidBody and the bug exists both in Bullet and GodotPhysics.

Body keeps gaining momentum with each bounce when linear and angular damp is set to 0. If you set both damps to 0.1 (which is default) then,

Minimal reproduction project for 3D: RigidBodyTest.zip

Xrayez commented 3 years ago

Biased velocity which is used to separate bodies in order to resolve interpenetration could contribute to gain in momentum. I'm currently developing my own physics engine and get the same results when restitution (bounce) is set to 1.0.

Increasing Engine.iterations_per_second to values like 300 helps to minimize this gain in momentum, and decreasing it to 30 makes it even more dramatic. So I guess this is also an error accumulated from integrating velocity/acceleration over large or small delta time (the smaller, the less error).

I'm really not sure if there's an efficient way to resolve this, but according to other engines/implementations, it seems to be a common limitation. Perhaps a better integration scheme could be incorporated, but that would be at the cost of performance.

CCD could also help this perhaps, but it's not working: #9071.

Body keeps gaining momentum with each bounce when linear and angular damp is set to 0. If you set both damps to 0.1 (which is default) then,

  • GodotPhysics: RigidBody bounces back to the same height

Perhaps this is one of the reasons why damp is set to 0.1 by default, to cover up those issues.