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