Add some early returns
This commit is contained in:
@@ -247,15 +247,8 @@ impl KinematicCharacterController {
|
||||
toi,
|
||||
});
|
||||
|
||||
if let Some(translation_on_slope) =
|
||||
self.handle_slopes(&toi, &mut translation_remaining, offset)
|
||||
{
|
||||
translation_remaining = translation_on_slope;
|
||||
println!("[slope] translation_on_slope: {translation_on_slope:?}");
|
||||
println!("[slope] translation_remaining: {translation_remaining:?}");
|
||||
} else {
|
||||
// If the slope is too big, try to step on the stair.
|
||||
let stair_handled = self.handle_stairs(
|
||||
if !self.handle_stairs(
|
||||
bodies,
|
||||
colliders,
|
||||
queries,
|
||||
@@ -266,17 +259,19 @@ impl KinematicCharacterController {
|
||||
handle,
|
||||
&mut translation_remaining,
|
||||
&mut result,
|
||||
);
|
||||
println!("[stair] translation_remaining: {translation_remaining:?}");
|
||||
println!("[stair]stair_handled: {stair_handled:?}");
|
||||
if !stair_handled {
|
||||
) {
|
||||
if let Some(translation_on_slope) =
|
||||
self.handle_slopes(&toi, &mut translation_remaining, offset)
|
||||
{
|
||||
translation_remaining = translation_on_slope;
|
||||
} else {
|
||||
// No slopes or stairs ahead; try to move along obstacles.
|
||||
let allowed_translation = subtract_hit(translation_remaining, &toi, offset);
|
||||
result.translation += allowed_translation;
|
||||
translation_remaining -= allowed_translation;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No interference along the path.
|
||||
result.translation += translation_remaining;
|
||||
@@ -490,6 +485,8 @@ impl KinematicCharacterController {
|
||||
// Check if there is a slope to climb.
|
||||
let angle_with_floor = self.up.angle(&hit.normal1);
|
||||
let climbing = self.up.dot(&slope_translation) >= 0.0;
|
||||
println!("angle_with_floor: {}, climbing: {}", angle_with_floor, climbing);
|
||||
println!("max_slope_climb_angle: {}, min_slope_slide_angle: {}", self.max_slope_climb_angle, self.min_slope_slide_angle);
|
||||
|
||||
climbing
|
||||
.then(||(angle_with_floor <= self.max_slope_climb_angle) // Are we allowed to climb?
|
||||
@@ -528,7 +525,10 @@ impl KinematicCharacterController {
|
||||
translation_remaining: &mut Vector<Real>,
|
||||
result: &mut EffectiveCharacterMovement,
|
||||
) -> bool {
|
||||
if let Some(autostep) = self.autostep {
|
||||
let autostep = match self.autostep {
|
||||
Some(autostep) => autostep,
|
||||
None => return false,
|
||||
};
|
||||
let min_width = autostep.min_width.eval(dims.x);
|
||||
let max_height = autostep.max_height.eval(dims.y);
|
||||
|
||||
@@ -549,10 +549,12 @@ impl KinematicCharacterController {
|
||||
|
||||
let shifted_character_pos = Translation::from(*self.up * max_height) * character_pos;
|
||||
|
||||
if let Some(horizontal_dir) = (*translation_remaining
|
||||
- *self.up * translation_remaining.dot(&self.up))
|
||||
.try_normalize(1.0e-5)
|
||||
{
|
||||
let horizontal_dir = match (*translation_remaining - *self.up * translation_remaining.dot(&self.up))
|
||||
.try_normalize(1.0e-5) {
|
||||
Some(dir) => dir,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
if queries
|
||||
.cast_shape(
|
||||
bodies,
|
||||
@@ -643,10 +645,7 @@ impl KinematicCharacterController {
|
||||
|
||||
result.translation += *self.up * step_height + horizontal_nudge;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
/// For a given collision between a character and its environment, this method will apply
|
||||
|
||||
Reference in New Issue
Block a user