Jelajahi Sumber

Merge pull request #110914 from mihe/jolt/multiple-contact-callbacks

Fix CCD bodies adding multiple contact manifolds when using Jolt
Thaddeus Crews 2 minggu lalu
induk
melakukan
e9cd9a9c35
1 mengubah file dengan 6 tambahan dan 0 penghapusan
  1. 6 0
      modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp

+ 6 - 0
modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp

@@ -193,6 +193,12 @@ bool JoltContactListener3D::_try_add_contacts(const JPH::Body &p_jolt_body1, con
 		return manifolds_by_shape_pair[shape_pair];
 	}();
 
+	if (unlikely(!manifold.contacts1.is_empty())) {
+		// CCD collisions can result in two contact callbacks for the same shape pair, one in the earlier discrete stage and one in the later CCD stage.
+		// We want the manifolds from the discrete stage, as the bodies still have their original velocities at that point, so we early-out if we've already stored something.
+		return false;
+	}
+
 	const JPH::uint contact_count = p_manifold.mRelativeContactPointsOn1.size();
 
 	manifold.contacts1.reserve((uint32_t)contact_count);