diff options
| author | Sébastien Crozet <developer@crozet.re> | 2023-03-26 14:56:04 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-26 14:56:04 +0200 |
| commit | e4e37b4d9cabe883887bae8495920973a36301c6 (patch) | |
| tree | 1fd77da5b20c2ec1add9ec0217e801d73eda27d5 /src/control/character_controller.rs | |
| parent | d3e1370f59277bc96bfafaf1ca38a203a34d44c3 (diff) | |
| parent | afe4e4d53d0ab15aff0830cd14bb77b71a112208 (diff) | |
| download | rapier-e4e37b4d9cabe883887bae8495920973a36301c6.tar.gz rapier-e4e37b4d9cabe883887bae8495920973a36301c6.tar.bz2 rapier-e4e37b4d9cabe883887bae8495920973a36301c6.zip | |
Merge pull request #470 from Jeff425/sliding_down_slope_output
#465 Add is_sliding_down_slope field to EffectiveCharacterMovement
Diffstat (limited to 'src/control/character_controller.rs')
| -rw-r--r-- | src/control/character_controller.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/control/character_controller.rs b/src/control/character_controller.rs index c919064..a5bcf3d 100644 --- a/src/control/character_controller.rs +++ b/src/control/character_controller.rs @@ -135,6 +135,8 @@ pub struct EffectiveCharacterMovement { pub translation: Vector<Real>, /// Is the character touching the ground after applying `EffectiveKineamticMovement::translation`? pub grounded: bool, + /// Is the character sliding down a slope due to slope angle being larger than `min_slope_slide_angle`? + pub is_sliding_down_slope: bool, } impl KinematicCharacterController { @@ -184,6 +186,7 @@ impl KinematicCharacterController { let mut result = EffectiveCharacterMovement { translation: Vector::zeros(), grounded: false, + is_sliding_down_slope: false, }; let dims = self.compute_dims(character_shape); @@ -258,7 +261,8 @@ impl KinematicCharacterController { &mut result, ) { // No stairs, try to move along slopes. - translation_remaining = self.handle_slopes(&toi, &translation_remaining); + translation_remaining = + self.handle_slopes(&toi, &translation_remaining, &mut result); } } else { // No interference along the path. @@ -472,13 +476,19 @@ impl KinematicCharacterController { false } - fn handle_slopes(&self, hit: &TOI, translation_remaining: &Vector<Real>) -> Vector<Real> { + fn handle_slopes( + &self, + hit: &TOI, + translation_remaining: &Vector<Real>, + result: &mut EffectiveCharacterMovement, + ) -> Vector<Real> { let [vertical_translation, horizontal_translation] = self.split_into_components(translation_remaining); let slope_translation = subtract_hit(*translation_remaining, hit); // Check if there is a slope to climb. let angle_with_floor = self.up.angle(&hit.normal1); + // We are climbing if the movement along the slope goes upward, and the angle with the // floor is smaller than pi/2 (in which case we hit some some sort of ceiling). // @@ -495,6 +505,7 @@ impl KinematicCharacterController { horizontal_translation } else { // Let it slide + result.is_sliding_down_slope = true; slope_translation } } |
