diff options
| author | Jan Nils Ferner <contact@jnferner.com> | 2023-01-27 15:50:41 +0100 |
|---|---|---|
| committer | Jan Nils Ferner <contact@jnferner.com> | 2023-01-27 15:50:41 +0100 |
| commit | fa9ab6c2bc80643e461b0ad5d0b9614a98831c87 (patch) | |
| tree | 8de06dae45ae5dd30d05fe504b181bbeb422455f /src/control | |
| parent | 247ed510b4fa08195fd54bf8736194a8d168783b (diff) | |
| download | rapier-fa9ab6c2bc80643e461b0ad5d0b9614a98831c87.tar.gz rapier-fa9ab6c2bc80643e461b0ad5d0b9614a98831c87.tar.bz2 rapier-fa9ab6c2bc80643e461b0ad5d0b9614a98831c87.zip | |
Fix uncontrolled sliding
Diffstat (limited to 'src/control')
| -rw-r--r-- | src/control/character_controller.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/control/character_controller.rs b/src/control/character_controller.rs index 06e7ff0..fa352ba 100644 --- a/src/control/character_controller.rs +++ b/src/control/character_controller.rs @@ -485,9 +485,11 @@ impl KinematicCharacterController { translation_remaining: &Vector<Real>, offset: Real, ) -> Option<Vector<Real>> { + let [vertical_translation, horizontal_translation] = + self.split_into_components(translation_remaining); let [vertical_slope_translation, horizontal_slope_translation] = - self.split_into_components(translation_remaining) - .map(|remaining| subtract_hit(remaining, hit, offset)); + [vertical_translation, horizontal_translation] + .map(|remaining| subtract_hit(remaining, hit, offset)); let slope_translation = horizontal_slope_translation + vertical_slope_translation; // Check if there is a slope to climb. @@ -496,10 +498,10 @@ impl KinematicCharacterController { climbing .then(||(angle_with_floor <= self.max_slope_climb_angle) // Are we allowed to climb? - .then_some(slope_translation)) + .then_some(horizontal_translation )) .unwrap_or_else(|| (angle_with_floor >= self.min_slope_slide_angle)// Are we allowed to slide? - .then_some(slope_translation) - .unwrap_or(horizontal_slope_translation) + .then_some(slope_translation ) + .unwrap_or(horizontal_translation) .into()) } |
