Skip to content

Commit

Permalink
Fix rotation change check in integrator (#284)
Browse files Browse the repository at this point in the history
# Objective

In #272, the integrator was changed to update rotation only if `delta.w != 0.0`. However, in some cases, x, y, or z can be non-zero even if w is zero, like with `AngularVelocity(Vec3::X)`, and in those cases the rotation would incorrectly be ignored.

## Solution

Make the condition stricter by also checking if x, y, and z are 0. Based on a quick test, this should also keep change detection working, which is what #272 was trying to address.
  • Loading branch information
Jondolf authored Dec 27, 2023
1 parent 8c00e09 commit 370354f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugins/integrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ fn integrate_rot(mut bodies: Query<RotIntegrationComponents, Without<Sleeping>>,
.extend(delta_secs * 0.5 * q.w);
// avoid triggering bevy's change detection unnecessarily
let delta = Quaternion::from_vec4(effective_dq);
if delta.w != 0.0 {
if delta != Quaternion::from_xyzw(0.0, 0.0, 0.0, 0.0) {
rot.0 = (rot.0 + delta).normalize();
}
}
Expand Down

0 comments on commit 370354f

Please sign in to comment.