bevy_xpbd icon indicating copy to clipboard operation
bevy_xpbd copied to clipboard

Default values for friction, restitution and damping should be globally configurable

Open Jondolf opened this issue 2 years ago • 0 comments
trafficstars

We should make it possible to configure the default values used for friction and restitution. It's annoying to set each body's friction separately if your world is full of ice, for example.

While we can't change the value returned by e.g. Restitution::default() at runtime, it should be very straightforward to do in the PreparePlugin when initializing missing components for bodies and colliders. We can store the default values in resources and use them for the default values of the components.

Naming

How do we want to name the resources? Do we want each component to have a separate resource, or should we group properties together?

Here are a few ideas:

// All separate
struct DefaultFriction(Friction);
struct DefaultRestitution(Restitution);
struct DefaultLinearDamping(Scalar);
struct DefaultAngularDamping(Scalar);

// Grouped
struct DefaultMaterialProperties {
    friction: Friction,
    restitution: Restitution,
}
struct DefaultDamping {
    linear: Scalar,
    angular: Scalar,
}

// All together
struct DefaultPhysicsProperties {
    friction: Friction,
    restitution: Restitution,
    linear_damping: Scalar,
    angular_damping: Scalar,
}

The Default could also be replaced by Global or World, whichever one is more clear.

Personally, I prefer the first option of using separate resources, since it's a bit more explicit and consistent in terms of our naming conventions, but if others have different ideas, feel free to share.

Jondolf avatar Aug 09 '23 07:08 Jondolf