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

Unexpected behavior with LockedAxes and rotations after upgrading from 0.1.0 to 0.1.1 #474

Closed
piedoom opened this issue Jul 31, 2024 · 1 comment · Fixed by #485
Closed
Labels
A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Bug Something isn't working

Comments

@piedoom
Copy link

piedoom commented Jul 31, 2024

Hello! I made a post in Discord, and managed to make a pretty simple reproduction of the issue. In 0.1.0, setting the AngularVelocity appears to function normally, but in 0.1.1, it appears to "stick" due to the LockedAxes component, which should not be affecting the rotation.

https://github.com/piedoom/av-repro

Specifically, the situation that causes the issue must have the following:

  • The entity must have a Transform with some rotation other than Y is up. In this example, Z is considered up. (I've actually only tested with Z up, but assume it can happen with other rotations?)
  • There must be LockedAxes. In my case, every rotation but around the Z axis is locked.

Videos of each version

0.1.0

Screen.Recording.2024-07-30.at.8.41.22.PM.mov

0.1.1

Screen.Recording.2024-07-30.at.8.41.52.PM.mov

Thank you and apologies if this is user error!

I noticed I could fix the behavior by specifying a regular transform for the entity, and then specifically adding a Rotation with Z as up (though this rotates the forward vector of my object downward, which is unwanted). Anyways, I'm wondering if there's perhaps a mismatch of the transform rotation and the physics rotation that is causing this

@Jondolf Jondolf added C-Bug Something isn't working A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on labels Jul 31, 2024
@Jondolf
Copy link
Owner

Jondolf commented Aug 10, 2024

Thank you for the useful reproduction! This seems to have been a regression caused by #420, as it applies the locked axes incorrectly. This should be fixed by #485.

Jondolf pushed a commit that referenced this issue Aug 19, 2024
# Objective

I think that #485 wasn't quite the right fix for #474 - applying locked axes to an inertia tensor zeros out one or more of its rows, making the matrix singular - taking the inverse then results in a matrix that's all NaNs, making the delta_ang_vel also all NaNs, which causes the angular momentum to be unaffected by anything that timestep (including applied torques!).

The problem with the status quo ante seems to be that a similar thing happened - rather than trying to invert the (singular) locked inverse inertia, the calculated Jacobian was (near-)singular in a lot of cases when axes were locked, and depending on round-off errors you'd either get NaNs or just an outright cancellation of the angular velocity

## Solution

Calculating the delta-ω from gyroscopic effects with an unconstrained inertia matrix and *then* applying the locked axes to that angular velocity increment should be more reliable, and should avoid undesirable NaN values showing up
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 a pull request may close this issue.

2 participants