浏览代码

Merge pull request #99397 from yosoyfreeman/master

Allow `apply_floor_snap` to preserve the horizontal position regardless of `stop_on_slopes`
Thaddeus Crews 10 月之前
父节点
当前提交
b88fd31687
共有 2 个文件被更改,包括 16 次插入16 次删除
  1. 8 8
      scene/2d/physics/character_body_2d.cpp
  2. 8 8
      scene/3d/physics/character_body_3d.cpp

+ 8 - 8
scene/2d/physics/character_body_2d.cpp

@@ -352,14 +352,14 @@ void CharacterBody2D::_apply_floor_snap(bool p_wall_as_floor) {
 			floor_normal = result.collision_normal;
 			floor_normal = result.collision_normal;
 			_set_platform_data(result);
 			_set_platform_data(result);
 
 
-			if (floor_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.
-				if (result.travel.length() > margin) {
-					result.travel = up_direction * up_direction.dot(result.travel);
-				} else {
-					result.travel = Vector2();
-				}
+			// Ensure that we only move the body along the up axis, because
+			// move_and_collide may stray the object a bit when getting it unstuck.
+			// Canceling this motion should not affect move_and_slide, as previous
+			// calls to move_and_collide already took care of freeing the body.
+			if (result.travel.length() > margin) {
+				result.travel = up_direction * up_direction.dot(result.travel);
+			} else {
+				result.travel = Vector2();
 			}
 			}
 
 
 			parameters.from.columns[2] += result.travel;
 			parameters.from.columns[2] += result.travel;

+ 8 - 8
scene/3d/physics/character_body_3d.cpp

@@ -469,14 +469,14 @@ void CharacterBody3D::apply_floor_snap() {
 		_set_collision_direction(result, result_state, CollisionState(true, false, false));
 		_set_collision_direction(result, result_state, CollisionState(true, false, false));
 
 
 		if (result_state.floor) {
 		if (result_state.floor) {
-			if (floor_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.
-				if (result.travel.length() > margin) {
-					result.travel = up_direction * up_direction.dot(result.travel);
-				} else {
-					result.travel = Vector3();
-				}
+			// Ensure that we only move the body along the up axis, because
+			// move_and_collide may stray the object a bit when getting it unstuck.
+			// Canceling this motion should not affect move_and_slide, as previous
+			// calls to move_and_collide already took care of freeing the body.
+			if (result.travel.length() > margin) {
+				result.travel = up_direction * up_direction.dot(result.travel);
+			} else {
+				result.travel = Vector3();
 			}
 			}
 
 
 			parameters.from.origin += result.travel;
 			parameters.from.origin += result.travel;