From e2812fcb0ff60d6484e4cc25bbb2765655cff42b Mon Sep 17 00:00:00 2001 From: fabriceci Date: Wed, 23 Mar 2022 10:24:35 +0100 Subject: When only a recovery occurs, don't report a collision on move_and_collide --- scene/2d/physics_body_2d.cpp | 6 +++++- scene/3d/physics_body_3d.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index eb4d9d6445..3cadbf7d25 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -58,7 +58,11 @@ Ref PhysicsBody2D::_move(const Vector2 &p_distance, bool p PhysicsServer2D::MotionParameters parameters(get_global_transform(), p_distance, p_margin); PhysicsServer2D::MotionResult result; - if (move_and_collide(parameters, result, p_test_only)) { + + bool collided = move_and_collide(parameters, result, p_test_only); + + // Don't report collision when the whole motion is done. + if (collided && result.collision_safe_fraction < 1) { // Create a new instance when the cached reference is invalid or still in use in script. if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) { motion_cache.instantiate(); diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 47baa9e023..72a9072cc3 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -96,7 +96,11 @@ Ref PhysicsBody3D::_move(const Vector3 &p_distance, bool p parameters.max_collisions = p_max_collisions; PhysicsServer3D::MotionResult result; - if (move_and_collide(parameters, result, p_test_only)) { + + bool collided = move_and_collide(parameters, result, p_test_only); + + // Don't report collision when the whole motion is done. + if (collided && result.collision_safe_fraction < 1) { // Create a new instance when the cached reference is invalid or still in use in script. if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) { motion_cache.instantiate(); -- cgit v1.2.3