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

Normalize rotations after solving constraints in solver #345

Merged
merged 2 commits into from
Mar 2, 2024

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Mar 2, 2024

Objective

Adopted from #237 by @mattdm, fixes #235.

Constraints update rotation by adding or subtracting quaternions. Unlike multiplying unit quaternions (the typical way to "add" together rotations), this can result in rotations becoming unnormalized. This can cause explosions (see #235), and cause panics when trying to rotate Bevy's direction types.

Solution

Normalize the rotations after the constraint rotation delta has been applied. This does come with a small extra cost, but I believe it is worth it for stability. The normalization is also present in some other XPBD implementations I've found, like this one.

@Jondolf Jondolf added bugfix A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on labels Mar 2, 2024
@Jondolf Jondolf merged commit b18437e into main Mar 2, 2024
4 checks passed
@Jondolf Jondolf deleted the normalize-in-solver branch March 2, 2024 17:16
@mattdm
Copy link
Sponsor Contributor

mattdm commented Mar 2, 2024

Sorry I didn't get back to this! January was busier than anticipated, and I've had covid for the whole last month. I'll be around again sometime!

@Jondolf Jondolf added C-Bug Something isn't working and removed bugfix labels Jul 19, 2024
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-Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rotations not normalized in solver, causing colliders to expand and eventually explode
2 participants