diff options
| author | Jan Hohenheim <jan@hohenheim.ch> | 2023-02-05 02:18:43 +0100 |
|---|---|---|
| committer | Jan Hohenheim <jan@hohenheim.ch> | 2023-02-05 02:18:43 +0100 |
| commit | fac561c902ec3d004d3f95df137beb3450231bc6 (patch) | |
| tree | 7873273eab5af464cc54c4a03e709a6219a89ac4 /src/control | |
| parent | 4ed3adda6ef243ccdba1752bb59f6ff40bd1881f (diff) | |
| download | rapier-fac561c902ec3d004d3f95df137beb3450231bc6.tar.gz rapier-fac561c902ec3d004d3f95df137beb3450231bc6.tar.bz2 rapier-fac561c902ec3d004d3f95df137beb3450231bc6.zip | |
Fix erroneous sliding
Diffstat (limited to 'src/control')
| -rw-r--r-- | src/control/character_controller.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/control/character_controller.rs b/src/control/character_controller.rs index 7ae0d5f..f7f7e2c 100644 --- a/src/control/character_controller.rs +++ b/src/control/character_controller.rs @@ -499,16 +499,20 @@ impl KinematicCharacterController { let angle_with_floor = self.up.angle(&hit.normal1); let climbing = self.up.dot(&slope_translation) >= 0.0; - if climbing { - // Are we allowed to climb? - (angle_with_floor <= self.max_slope_climb_angle).then_some(slope_translation) - } - // Are we forced to slide? - else if angle_with_floor >= self.min_slope_slide_angle { - slope_translation.into() - } else { - horizontal_translation.into() - } + climbing + .then(|| { + (angle_with_floor <= self.max_slope_climb_angle) // Are we allowed to climb? + .then_some(horizontal_translation) + }) + .unwrap_or_else(|| { + // Are we allowed to slide? + if angle_with_floor >= self.min_slope_slide_angle { + slope_translation + } else { + horizontal_translation + } + .into() + }) } fn split_into_components(&self, translation: &Vector<Real>) -> [Vector<Real>; 2] { |
