|
@@ -345,10 +345,21 @@ struct _RigidBody2DInOut {
|
|
|
|
|
|
bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, float p_margin, const Ref<Physics2DTestMotionResult> &p_result) {
|
|
bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, float p_margin, const Ref<Physics2DTestMotionResult> &p_result) {
|
|
Physics2DServer::MotionResult *r = nullptr;
|
|
Physics2DServer::MotionResult *r = nullptr;
|
|
|
|
+ Physics2DServer::MotionResult temp_result;
|
|
if (p_result.is_valid()) {
|
|
if (p_result.is_valid()) {
|
|
r = p_result->get_result_ptr();
|
|
r = p_result->get_result_ptr();
|
|
|
|
+ } else {
|
|
|
|
+ r = &temp_result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bool colliding = Physics2DServer::get_singleton()->body_test_motion(get_rid(), get_global_transform(), p_motion, p_infinite_inertia, p_margin, r);
|
|
|
|
+
|
|
|
|
+ if (colliding) {
|
|
|
|
+ // Don't report collision when the whole motion is done.
|
|
|
|
+ return (r->collision_safe_fraction < 1.0);
|
|
|
|
+ } else {
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
- return Physics2DServer::get_singleton()->body_test_motion(get_rid(), get_global_transform(), p_motion, p_infinite_inertia, p_margin, r);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void RigidBody2D::_direct_state_changed(Object *p_state) {
|
|
void RigidBody2D::_direct_state_changed(Object *p_state) {
|
|
@@ -1299,7 +1310,15 @@ Vector2 KinematicBody2D::get_floor_velocity() const {
|
|
bool KinematicBody2D::test_move(const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia) {
|
|
bool KinematicBody2D::test_move(const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia) {
|
|
ERR_FAIL_COND_V(!is_inside_tree(), false);
|
|
ERR_FAIL_COND_V(!is_inside_tree(), false);
|
|
|
|
|
|
- return Physics2DServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia, margin);
|
|
|
|
|
|
+ Physics2DServer::MotionResult result;
|
|
|
|
+ bool colliding = Physics2DServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia, margin, &result);
|
|
|
|
+
|
|
|
|
+ if (colliding) {
|
|
|
|
+ // Don't report collision when the whole motion is done.
|
|
|
|
+ return (result.collision_safe_fraction < 1.0);
|
|
|
|
+ } else {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void KinematicBody2D::set_safe_margin(float p_margin) {
|
|
void KinematicBody2D::set_safe_margin(float p_margin) {
|