diff options
author | Camille Mohr-Daurat <pouleyKetchoup@gmail.com> | 2021-11-23 11:22:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 11:22:17 -0700 |
commit | c6022ddcf371c5e5c8ee60d82329139d3bb6c438 (patch) | |
tree | 5034e23b941df875f979e13a920b2579f5b80199 /scene | |
parent | 7b0458c18f21cebc5ab1e6739e30e8ed36f0273f (diff) | |
parent | ed9b18be94b1786b23d8e302621502d61d8f48b5 (diff) |
Merge pull request #55254 from fabriceci/fix-horizontal-velocity-being-always-reset-on-wall
Fix horizontal velocity being always reset when the body hit a wall in 3D
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/physics_body_3d.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index edaf76bc3e..393e29e398 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -1328,8 +1328,15 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo // Apply slide on forward in order to allow only lateral motion on next step. Vector3 forward = wall_normal.slide(up_direction).normalized(); motion = motion.slide(forward); - // Avoid accelerating when you jump on the wall and smooth falling. - motion_velocity = motion_velocity.slide(forward); + + // Scales the horizontal velocity according to the wall slope. + if (vel_dir_facing_up) { + Vector3 slide_motion = motion_velocity.slide(result.collisions[0].normal); + // Keeps the vertical motion from motion_velocity and add the horizontal motion of the projection. + motion_velocity = up_direction * up_direction.dot(motion_velocity) + slide_motion.slide(up_direction); + } else { + motion_velocity = motion_velocity.slide(forward); + } // Allow only lateral motion along previous floor when already on floor. // Fixes slowing down when moving in diagonal against an inclined wall. |