diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-11-10 11:20:02 -0700 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-11-10 11:20:02 -0700 |
commit | 5da057adaf2127deaf1455641ccbe024f29f1ebd (patch) | |
tree | 5ecdf3db3afde0f1bab7d902c0b82d629abb6158 /scene/3d | |
parent | e8870ddefc36f6e04dc6212ab5ca1d6391739539 (diff) |
Fix test_move reporting collision when touching another body
Reporting rest collision information is needed for move_and_collide and
move_and_slide so floor detection can be done properly, but in the case
of just testing the motion for collision, it makes sense to return false
if the body is able to move all along the path without being stopped.
Updated the logic in test_move and clarified the documentation for
test_move and move_and_collide.
Diffstat (limited to 'scene/3d')
-rw-r--r-- | scene/3d/physics_body_3d.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index d0506227b4..058a854663 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -174,9 +174,12 @@ bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_linear ERR_FAIL_COND_V(!is_inside_tree(), false); PhysicsServer3D::MotionResult *r = nullptr; + PhysicsServer3D::MotionResult temp_result; if (r_collision.is_valid()) { // Needs const_cast because method bindings don't support non-const Ref. r = const_cast<PhysicsServer3D::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 @@ -184,7 +187,14 @@ bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_linear PhysicsServer3D::MotionParameters parameters(p_from, p_linear_velocity * delta, p_margin); - return PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), parameters, r); + bool colliding = PhysicsServer3D::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; + } } void PhysicsBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) { |