소스 검색

Make it possible to call move_and_slide from _process, even if it is not recommended

Previously, it would reuse the _physics_process delta, causing it to move faster on faster framerates

Fixes #17516
Bojidar Marinov 7 년 전
부모
커밋
d94c76a199
2개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 1
      scene/2d/physics_body_2d.cpp
  2. 2 1
      scene/3d/physics_body.cpp

+ 2 - 1
scene/2d/physics_body_2d.cpp

@@ -1237,7 +1237,8 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const
 		}
 	}
 
-	Vector2 motion = (floor_motion + p_linear_velocity) * get_physics_process_delta_time();
+	// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
+	Vector2 motion = (floor_motion + p_linear_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
 	Vector2 lv = p_linear_velocity;
 
 	on_floor = false;

+ 2 - 1
scene/3d/physics_body.cpp

@@ -1167,7 +1167,8 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve
 		}
 	}
 
-	Vector3 motion = (floor_velocity + lv) * get_physics_process_delta_time();
+	// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
+	Vector3 motion = (floor_velocity + lv) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
 
 	on_floor = false;
 	on_ceiling = false;