diff options
| author | Jan Hohenheim <jan@hohenheim.ch> | 2023-02-09 00:56:16 +0100 |
|---|---|---|
| committer | Jan Hohenheim <jan@hohenheim.ch> | 2023-02-09 00:56:16 +0100 |
| commit | dd195a47203ec4d9540f1a656ac53859372d353f (patch) | |
| tree | c07e2b1b6e6ef8e058854810b634e439d02cb621 /src | |
| parent | 1b449fc31df6b9ecb8d339a5ff5fb2c1763a7978 (diff) | |
| download | rapier-dd195a47203ec4d9540f1a656ac53859372d353f.tar.gz rapier-dd195a47203ec4d9540f1a656ac53859372d353f.tar.bz2 rapier-dd195a47203ec4d9540f1a656ac53859372d353f.zip | |
Fix horizontal jittering along walls in 3D
Diffstat (limited to 'src')
| -rw-r--r-- | src/control/character_controller.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/control/character_controller.rs b/src/control/character_controller.rs index 66d2d11..0de897b 100644 --- a/src/control/character_controller.rs +++ b/src/control/character_controller.rs @@ -259,12 +259,12 @@ impl KinematicCharacterController { ) { // No stairs, try to move along slopes. if let Some(translation_on_slope) = - self.handle_slopes(&toi, &translation_remaining, offset) + self.handle_slopes(&toi, &translation_remaining) { translation_remaining = translation_on_slope; } else if allowed_dist.abs() < 1.0e5 { // No slopes or stairs ahead, but we didn't move yet; try to move along obstacle. - let allowed_translation = subtract_hit(translation_remaining, &toi, offset); + let allowed_translation = subtract_hit(translation_remaining, &toi); result.translation += allowed_translation; translation_remaining -= allowed_translation; } @@ -485,13 +485,12 @@ impl KinematicCharacterController { &self, hit: &TOI, translation_remaining: &Vector<Real>, - offset: Real, ) -> Option<Vector<Real>> { let [vertical_translation, horizontal_translation] = self.split_into_components(translation_remaining); let [vertical_slope_translation, horizontal_slope_translation] = [vertical_translation, horizontal_translation] - .map(|remaining| subtract_hit(remaining, hit, offset)); + .map(|remaining| subtract_hit(remaining, hit)); let slope_translation = horizontal_slope_translation + vertical_slope_translation; // Check if there is a slope to climb. @@ -618,7 +617,7 @@ impl KinematicCharacterController { ) { let [vertical_slope_translation, horizontal_slope_translation] = self .split_into_components(translation_remaining) - .map(|remaining| subtract_hit(remaining, &hit, offset)); + .map(|remaining| subtract_hit(remaining, &hit)); let slope_translation = horizontal_slope_translation + vertical_slope_translation; @@ -745,8 +744,9 @@ impl KinematicCharacterController { } } -fn subtract_hit(translation: Vector<Real>, hit: &TOI, offset: Real) -> Vector<Real> { - let surface_correction = translation.dot(&hit.normal1).abs(); - let surface_correction = surface_correction + offset; +fn subtract_hit(translation: Vector<Real>, hit: &TOI) -> Vector<Real> { + let surface_correction = (-translation).dot(&hit.normal1).max(0.0); + // This fixes some instances of moving through walls + let surface_correction = surface_correction * (1.0 + 1.0e-5); translation + *hit.normal1 * surface_correction } |
