Skip to content

Improvements to friction and restitution#551

Merged
Jondolf merged 12 commits into
mainfrom
rework-friction-and-restitution
Nov 9, 2024
Merged

Improvements to friction and restitution#551
Jondolf merged 12 commits into
mainfrom
rework-friction-and-restitution

Conversation

@Jondolf

@Jondolf Jondolf commented Nov 8, 2024

Copy link
Copy Markdown
Member

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-Feature A new feature, making something new possible A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide 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
@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-Feature A new feature, making something new possible M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change default coefficient of restitution to 0.0 Default values for friction, restitution and damping should be globally configurable

1 participant