Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RigidDynamicBody contacts in 2D and 3D #55602

Merged
merged 2 commits into from
Dec 6, 2021

Conversation

pouleyKetchoupp
Copy link
Contributor

Improved rigid body contacts and physics server contact settings, separated in two commits to make it easier to read.

Causes slight compatibility breakage because of changing physics server parameters and their default values.

First commit: main changes in rigid body contacts
Changed the algorithm for solving contacts to keep previous contacts as long as they are under the max separation threshold to keep contact impulses more consistent and contacts more stable.

Also made 2D consistent with 3D and changed some default parameters:
-Contact bias is now 0.8 instead of 0.3 to avoid springy contacts
-Solver iterations are 16 instead of 8 by default for better stability

Performance considerations:
Tested with stress tests that include lots of contacts from overlapping bodies.
3D: There's no measurable difference in performance.
2D: Performance is a bit lower (close to 10% slower in extreme cases)
The benefit for 2D physics to be much more stable outweighs the slight decrease in performance, and this could be alleviated by changing the algorithm to use jacobians for contact solving to help with cache efficiency and memory allocations.

Second commit: Update space parameters in 2D and 3D
Clarified space parameters for contacts and added missing ones.

List of changes:
-Add contact bias to space parameters
-Add solver iterations to space parameters, instead of a specific physics server function
-Renamed BODY_MAX_ALLOWED_PENETRATION to CONTACT_MAX_ALLOWED_PENETRATION to make it consistent with other contact parameters


Tests with stack of boxes from the 2D and 3D physics test demos:
godotengine/godot-demo-projects#638

Now they work fine in 2D and 3D, even with the increased 2D gravity in 4.0.

Before After
Pile of boxes 2D
Pile of boxes 3D
Push boxes 2D

Fixed bugs:

Fixes #2092 - Pile of RigidBody2Ds results in overlapping and shaking
C:\Users\bourr\Downloads\godot-projects\test_rigidbody-4.0
4.0 project: test_rigidbody-4.0.zip
Same project as original MVP, with gravity set to 98 to match the default from 3.x

Fixes #34215 - 2D Physics Collision is 'Squishy'
4.0 project: Bouncy-4.0.zip

Fixes #29303 - Rigid bodies using inertia become unstable.
4.0 project: RigidBody.Bug-4.0.zip
Same project as MVP, with more reasonable values for inertia to help with stability (no more than 20 times the default amount of rotation, which was still causing issues in 3.x).
Works well now, even with gravity 10 times higher in 4.0.

Changed the algorithm for solving contacts to keep previous contacts as
long as they are under the max separation threshold to keep contact
impulses more consistent and contacts more stable.

Also made 2D consistent with 3D and changed some default parameters:
-Contact bias is now 0.8 instead of 0.3 to avoid springy contacts
-Solver iterations are 16 instead of 8 by default for better stability

Performance considerations:
Tested with stress tests that include lots of contacts from overlapping
bodies.
3D: There's no measurable difference in performance.
2D: Performance is a bit lower (close to 10% slower in extreme cases)
The benefit for 2D physics to be much more stable outweighs the slight
decrease in performance, and this could be alleviated by changing the
algorithm to use jacobians for contact solving to help with cache
efficiency and memory allocations.
Clarified space parameters for contacts and added missing ones.

List of changes:
-Add contact bias to space parameters
-Add solver iterations to space parameters, instead of a specific
physics server function
-Renamed BODY_MAX_ALLOWED_PENETRATION to CONTACT_MAX_ALLOWED_PENETRATION
to make it consistent with other contact parameters
Copy link
Contributor

@fabriceci fabriceci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with a custom tests, there is a big improvement, on piles indeed but on the overall stability.

@pouleyKetchoupp as you can see, it's maybe not related to the PR, but the contact points are not displayed after. Can you just verify that on your side? not related, fixed few days ago by #55486

Before:

before.mp4

After:

cube.fall.mp4

servers/physics_2d/godot_body_pair_2d.h Show resolved Hide resolved
@akien-mga akien-mga merged commit 4bce5e3 into godotengine:master Dec 6, 2021
@akien-mga
Copy link
Member

Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants