summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <juan@godotengine.org>2019-02-23 10:23:38 -0300
committerJuan Linietsky <juan@godotengine.org>2019-02-23 10:24:21 -0300
commit9dfe3b6d9e94c74d70f8241763a9d010c4a6db1e (patch)
treec99ace8919a7f4ded4639e3d7e260dfd1a2461ea /scene
parent24097811e498afafdd7bb4d012d0b8759d0115e7 (diff)
Ensure move and slide snap respects stop on slope, fixes #26180
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/physics_body_2d.cpp6
-rw-r--r--scene/3d/physics_body.cpp5
2 files changed, 11 insertions, 0 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index ce80bc508e..eeabe15b08 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -1341,6 +1341,12 @@ Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_veloci
on_floor = true;
on_floor_body = col.collider_rid;
floor_velocity = col.collider_vel;
+ if (p_stop_on_slope) {
+ // move and collide may stray the object a bit because of pre un-stucking,
+ // so only ensure that motion happens on floor direction in this case.
+ col.travel = p_floor_direction * p_floor_direction.dot(col.travel);
+ }
+
} else {
apply = false;
}
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index f85b51af08..ab1eed0859 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -1288,6 +1288,11 @@ Vector3 KinematicBody::move_and_slide_with_snap(const Vector3 &p_linear_velocity
on_floor = true;
on_floor_body = col.collider_rid;
floor_velocity = col.collider_vel;
+ if (p_stop_on_slope) {
+ // move and collide may stray the object a bit because of pre un-stucking,
+ // so only ensure that motion happens on floor direction in this case.
+ col.travel = p_floor_direction * p_floor_direction.dot(col.travel);
+ }
} else {
apply = false; //snapped with floor direction, but did not snap to a floor, do not snap.
}