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

Clamp coefficient of restitution between 0 and 1 and improve restitution docs #118

Merged
merged 4 commits into from
Aug 9, 2023

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Aug 9, 2023

Clamps each Restitution coefficient to be between 0 and 1, adds the associated constants Restitution::PERFECTLY_INELASTIC and Restitution::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.

@Jondolf Jondolf added C-Docs Improvements or additions to documentation C-Enhancement New feature or request labels Aug 9, 2023
@Jondolf Jondolf merged commit ad20658 into main Aug 9, 2023
3 checks passed
@Jondolf Jondolf deleted the restitution-clamping branch August 9, 2023 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Docs Improvements or additions to documentation C-Enhancement New feature or request
Projects
None yet
1 participant