diff options
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 9d140f744f..5ec2a81108 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -133,9 +133,12 @@ bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_linear ERR_FAIL_COND_V(!is_inside_tree(), false); PhysicsServer2D::MotionResult *r = nullptr; + PhysicsServer2D::MotionResult temp_result; if (r_collision.is_valid()) { // Needs const_cast because method bindings don't support non-const Ref. r = const_cast<PhysicsServer2D::MotionResult *>(&r_collision->result); + } else { + r = &temp_result; } // Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky. @@ -143,7 +146,14 @@ bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_linear PhysicsServer2D::MotionParameters parameters(p_from, p_linear_velocity * delta, p_margin); - return PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), parameters, r); + bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), parameters, r); + + if (colliding) { + // Don't report collision when the whole motion is done. + return (r->collision_safe_fraction < 1.0); + } else { + return false; + } } TypedArray<PhysicsBody2D> PhysicsBody2D::get_collision_exceptions() { |