From 247ed510b4fa08195fd54bf8736194a8d168783b Mon Sep 17 00:00:00 2001 From: Jan Nils Ferner Date: Fri, 27 Jan 2023 15:08:41 +0100 Subject: Fix horizontal offset not being respected --- src/control/character_controller.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/control') diff --git a/src/control/character_controller.rs b/src/control/character_controller.rs index ec0e04e..06e7ff0 100644 --- a/src/control/character_controller.rs +++ b/src/control/character_controller.rs @@ -228,13 +228,13 @@ impl KinematicCharacterController { &(Translation::from(result.translation) * character_pos), &translation_dir, character_shape, - translation_dist - offset, + translation_dist, false, filter, ) { // We hit something, compute the allowed self. let allowed_dist = - (toi.toi - (-toi.normal1.dot(&translation_dir)) * offset).max(0.0); + toi.toi - (toi.normal1.dot(&translation_dir)).abs() * offset; let allowed_translation = *translation_dir * allowed_dist; result.translation += allowed_translation; translation_remaining -= allowed_translation; @@ -337,7 +337,7 @@ impl KinematicCharacterController { &-self.up, character_shape, snap_distance, - true, + false, filter, ) { // Apply the snap. @@ -738,6 +738,7 @@ impl KinematicCharacterController { } fn subtract_hit(translation: Vector, hit: &TOI, offset: Real) -> Vector { - let surface_correction = translation.dot(&hit.normal1) * (1.0 + offset); - translation - *hit.normal1 * surface_correction + let surface_correction = translation.dot(&hit.normal1).abs(); + let surface_correction = surface_correction + offset; + translation + *hit.normal1 * surface_correction } -- cgit