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

Improvements to friction and restitution #551

Merged
merged 12 commits into from
Nov 9, 2024

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Nov 8, 2024

Objective

Fixes #503
Partially fixes #119

Currently, Friction and Restitution are inserted automatically. Bodies are bouncy by default, with a coefficient of restitution of 0.3. Coefficients of static and dynamic friction are also 0.3.

I gathered some default values used for coefficients and combine rules in other engines:

  • Jolt: 0 restitution (max), 0.2 friction (geometric mean)
  • Box2D: 0 restitution (max), 0.6 friction (geometric mean)
  • PhysX: 0 restitution (average), 0 friction (average)
  • Rapier: 0 restitution (average), 0.5 friction (average)
  • Godot: 0 restitution (?), 1.0 friction ("rough" boolean)
  • Unity 2D: 0 restitution (max), 0.4 friction (geometric mean)
  • Unity 3D: 0 restitution (average), 0.6 friction (average)

There's a lot of variation here, but everything except Avian defaults to zero restitution. It makes sense for bounciness to be opt-in, and it's good for performance. Friction also tends to be higher, and indeed Avian's default friction feels quite slidey.

Some engines also use a geometric mean sqrt(a * b) for the friction combine rule, which we don't currently support.

We should change to more sensible defaults, and also make the default values globally configurable, like in Unity. Different games have different needs and preferences, and it should be possible to use the best default that works for you.

Solution

  • Change default Friction coefficients to 0.5
  • Change default Restitution coefficient to 0.0
  • Add CoefficientCombine::GeometricMean as an option
  • Remove requirement for Friction and Restitution
  • Add DefaultFriction and DefaultRestitution resources, which are used for bodies with no Friction or Restitution specified
  • Remove restitution clamping (values greater than 1.0 should be allowed, though not recommended)
  • Substantially improve documentation for friction and restitution

Migration Guide

Friction and Restitution are no longer inserted automatically for rigid bodies. Instead, there are now DefaultFriction and DefaultRestitution resources, which are used for bodies with no Friction or Restitution specified. These resources can be configured to change the global defaults for friction and restitution.

The default restitution is now 0.0, meaning that bodies are no longer bouncy by default. The default coefficients of friction have also been increased from 0.3 to 0.5.

@Jondolf Jondolf added C-Enhancement New feature or request A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt labels Nov 8, 2024
@Jondolf Jondolf added this to the 0.2 milestone Nov 8, 2024
@Jondolf Jondolf enabled auto-merge (squash) November 9, 2024 22:11
@Jondolf Jondolf merged commit 734118b into main Nov 9, 2024
4 checks passed
@Jondolf Jondolf deleted the rework-friction-and-restitution branch November 10, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt C-Enhancement New feature or request
Projects
None yet
1 participant