Skip to content

Commit

Permalink
fix(character_movement): Fix sleeping kinematic / has_moved optimizat…
Browse files Browse the repository at this point in the history
…ion causing AI to sink into ground (#883)

I seem to have set the update of saved positions used to determine if
kinematic has moved in the wrong spot, ended up in a situation in which
AI thinks it had not moved, but was inching down by -0.1 each frame,
sinking into ground.

I was able to repro fairly consistently and feeling pretty confident
this should fix the AI sinking into ground described in #882. (Though I
do not believe this is related to the losing control of player bit).

EDIT: #853 (objects stuck in walls) also appears to be resolved by this
fix.
  • Loading branch information
MaxCWhitehead committed Dec 19, 2023
1 parent a828769 commit cc6ef36
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/physics.rs
Expand Up @@ -173,6 +173,11 @@ fn update_kinematic_bodies(
|| body.last_update_rotation != rotation
|| body.is_spawning // Don't consider new objects
};

let transform = transforms.get_mut(entity).unwrap();
body.last_update_position = transform.translation.xy();
body.last_update_rotation = transform.rotation.to_euler(EulerRot::XYZ).2;

if body.has_mass && has_moved {
puffin::profile_scope!("Shove objects out of walls");

Expand Down Expand Up @@ -344,10 +349,6 @@ fn update_kinematic_bodies(
body.shape,
);
}

let transform = transforms.get_mut(entity).unwrap();
body.last_update_position = transform.translation.xy();
body.last_update_rotation = transform.rotation.to_euler(EulerRot::XYZ).2;
}
}

Expand Down

0 comments on commit cc6ef36

Please sign in to comment.