aboutsummaryrefslogtreecommitdiff
path: root/src/control/character_controller.rs
diff options
context:
space:
mode:
authorJan Nils Ferner <contact@jnferner.com>2023-01-26 19:18:57 +0100
committerJan Nils Ferner <contact@jnferner.com>2023-01-26 19:18:57 +0100
commitbf3cc98489663829e2a65405774b36a6b6942c9a (patch)
treeddda90b7d92818cda171d71d718ca36028b51872 /src/control/character_controller.rs
parent000c759b78193f2e646861435aba6405eb014ed7 (diff)
downloadrapier-bf3cc98489663829e2a65405774b36a6b6942c9a.tar.gz
rapier-bf3cc98489663829e2a65405774b36a6b6942c9a.tar.bz2
rapier-bf3cc98489663829e2a65405774b36a6b6942c9a.zip
Simplify unused code
Diffstat (limited to 'src/control/character_controller.rs')
-rw-r--r--src/control/character_controller.rs35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/control/character_controller.rs b/src/control/character_controller.rs
index 25fb288..37a76fe 100644
--- a/src/control/character_controller.rs
+++ b/src/control/character_controller.rs
@@ -251,7 +251,7 @@ impl KinematicCharacterController {
toi,
});
- if let (Some(translation_on_slope), _) =
+ if let Some(translation_on_slope) =
self.handle_slopes(&toi, &mut translation_remaining)
{
println!("[slope] translation_on_slope: {translation_on_slope:?}");
@@ -478,33 +478,32 @@ impl KinematicCharacterController {
&self,
hit: &TOI,
translation_remaining: &Vector<Real>,
- ) -> (Option<Vector<Real>>, Real) {
+ ) -> Option<Vector<Real>> {
let vertical_translation_remaining = *self.up * (self.up.dot(translation_remaining));
let horizontal_translation_remaining =
*translation_remaining - vertical_translation_remaining;
- // The idea behind this `if` statement is as follows:
- // - If there is any amount of horizontal translations, then the intended
- // climb/slide down movement is decided by that translation.
- // - If there is no horizontal translation, then we only have gravity. In that case,
- // we take the vertical movement into account to decide if we need to slide down.
- let sliding_translation_remaining =
- translation_remaining
- - *hit.normal1 * (translation_remaining).dot(&hit.normal1);
+ let horizontal_translation_remaining =
+ horizontal_translation_remaining
+ - *hit.normal1 * (horizontal_translation_remaining).dot(&hit.normal1);
+
+ let vertical_translation_remaining =
+ vertical_translation_remaining
+ - *hit.normal1 * (vertical_translation_remaining).dot(&hit.normal1);
- println!("[slope] sliding_translation_remaining: {sliding_translation_remaining:?}");
+ let sliding_translation_remaining = horizontal_translation_remaining + vertical_translation_remaining;
- // Check if there is a slope we can climb.
+ // Check if there is a slope to climb.
let angle_with_floor = self.up.angle(&hit.normal1);
let climbing = self.up.dot(&sliding_translation_remaining) >= 0.0;
climbing
- .then(||(angle_with_floor <= self.max_slope_climb_angle)
- .then_some((Some(sliding_translation_remaining), angle_with_floor))
- .unwrap_or((None, angle_with_floor)))
- .unwrap_or_else(|| (angle_with_floor >= self.min_slope_slide_angle)
- .then_some((Some(sliding_translation_remaining), -angle_with_floor))
- .unwrap_or((Some(horizontal_translation_remaining), -angle_with_floor)))
+ .then(||(angle_with_floor <= self.max_slope_climb_angle) // Are we allowed to climb?
+ .then_some(Some(sliding_translation_remaining))
+ .unwrap_or(None))
+ .unwrap_or_else(|| (angle_with_floor >= self.min_slope_slide_angle)// Are we allowed to slide?
+ .then_some(Some(sliding_translation_remaining))
+ .unwrap_or(Some(horizontal_translation_remaining)))
}
fn handle_stairs(