Merge pull request #59438 from fabriceci/fix-move-and-collide-reported-collisions

Fix wrong collision reported on move_and_collide
This commit is contained in:
Rémi Verschelde 2022-04-28 18:47:22 +02:00 committed by GitHub
commit 212989d467
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -96,7 +96,11 @@ Ref<KinematicCollision3D> 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();