Skip to content

Commit

Permalink
Merge pull request godotengine#55202 from fabriceci/fix-wall-accelera…
Browse files Browse the repository at this point in the history
…tion-in-3d

Fix wall acceleration in move and slide (3D)
  • Loading branch information
pouleyKetchoupp authored Nov 22, 2021
2 parents 76aa1d0 + b738af8 commit 66ba19a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions scene/3d/physics_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1299,22 +1299,25 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
// in order to avoid blocking lateral motion along a wall.
if (motion_angle < .5 * Math_PI) {
apply_default_sliding = false;

if (p_was_on_floor && !vel_dir_facing_up) {
// Cancel the motion.
Transform3D gt = get_global_transform();
real_t travel_total = result.travel.length();
real_t cancel_dist_max = MIN(0.1, margin * 20);
if (travel_total <= margin + CMP_EPSILON) {
gt.origin -= result.travel;
result.travel = Vector3(); // Cancel for constant speed computation.
} else if (travel_total < cancel_dist_max) { // If the movement is large the body can be prevented from reaching the walls.
gt.origin -= result.travel.slide(up_direction);
// Keep remaining motion in sync with amount canceled.
motion = motion.slide(up_direction);
result.travel = Vector3();
} else {
// Travel is too high to be safely cancelled, we take it into account.
result.travel = result.travel.slide(up_direction);
motion = motion.normalized() * result.travel.length();
}
set_global_transform(gt);
result.travel = Vector3(); // Cancel for constant speed computation.

// Determines if you are on the ground, and limits the possibility of climbing on the walls because of the approximations.
_snap_on_floor(true, false);
} else {
Expand Down

0 comments on commit 66ba19a

Please sign in to comment.