Jondolf / avian

ECS-driven 2D and 3D physics engine for the Bevy game engine.
https://crates.io/crates/avian3d
Apache License 2.0
1.55k stars 120 forks source link

Remove `rest_length` field from `DistanceJoint`. #517

Open shanecelis opened 2 months ago

shanecelis commented 2 months ago

Objective

Remove rest_length from DistanceJoint which is ignored if length_limits is present.

Problem

I was using distance joints as muscles, changing their rest length to exert them. However, when I set the length_limits, nothing worked anymore. I looked into the code and saw my error: rest_length is ignored when length_limits is set, which seems like a foot gun to me. A TODO in the code said "Remove rest_length" and after surveying the code, I agreed.

Solution

I removed rest_length and with_rest_length() from DistanceJoint.

I changed the name and arguments of with_limits() to with_length_limits(). I think this makes it clearer that it's associated with the length_limits field. And I altered the arguments to accept Into<DistanceLimit>, so that it can be set with a Scalar, a pair of Scalars, or a DistanceLimit. My hope was that with_length_limits() could serve in place of both with_limits() and with_rest_length().

Auxillary Changes

Some doc tests weren't passing. I added the necessary ampersands (&) to make them pass.


Changelog

Migration Guide