Clamp coefficient of restitution between 0 and 1 and improve restitution docs #118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Clamps each
Restitution
coefficient to be between 0 and 1, adds the associated constantsRestitution::PERFECTLY_INELASTIC
andRestitution::PERFECTLY_ELASTIC
, and significantly improves the restitution docs. This closes #114 and #115.The clamping avoids issues with unrealistic and explosive behavior when users try to use values that are negative or over 1, which makes things more user-friendly and realistic. For the rare cases where you want bodies to gain kinetic energy on contact, you should implement it manually to work for your specific case in a stable manner.
The main caveat is that you can no longer multiply e.g. 0.5 and 2.0 to get 1.0 when combining coefficients, since 2.0 gets clamped to 1.0, which results in a final coefficient of 0.5. However, I find this clamping to be more explicit since it's clamping the actual component values and not internally clamping just the combined coefficient, and engines like Unity seem to be doing it like this as well. It also allows us to perform the clamping at initialization and not individually for each contact.