From 7a414dfb01b93f9150ad0796f1da8d805dec3ecc Mon Sep 17 00:00:00 2001 From: Mikael Hermansson Date: Tue, 17 Dec 2024 23:09:32 +0100 Subject: [PATCH] Stop reporting contacts for sleeping bodies when using Jolt Physics (cherry picked from commit 5bbdb4a770d81b73863a88fcb74dbe3c86f024a4) --- .../spaces/jolt_contact_listener_3d.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp b/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp index 184689e2ae2..6a02ef9622b 100644 --- a/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp +++ b/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp @@ -409,24 +409,28 @@ void JoltContactListener3D::_flush_contacts() { const JPH::SubShapeIDPair &shape_pair = E.key; Manifold &manifold = E.value; - const JPH::BodyID body_ids[2] = { shape_pair.GetBody1ID(), shape_pair.GetBody2ID() }; - const JoltReadableBodies3D jolt_bodies = space->read_bodies(body_ids, 2); + const JoltReadableBody3D jolt_body1 = space->read_body(shape_pair.GetBody1ID()); + const JoltReadableBody3D jolt_body2 = space->read_body(shape_pair.GetBody2ID()); - JoltBody3D *body1 = jolt_bodies[0].as_body(); + JoltBody3D *body1 = jolt_body1.as_body(); ERR_FAIL_NULL(body1); - JoltBody3D *body2 = jolt_bodies[1].as_body(); + JoltBody3D *body2 = jolt_body2.as_body(); ERR_FAIL_NULL(body2); const int shape_index1 = body1->find_shape_index(shape_pair.GetSubShapeID1()); const int shape_index2 = body2->find_shape_index(shape_pair.GetSubShapeID2()); - for (const Contact &contact : manifold.contacts1) { - body1->add_contact(body2, manifold.depth, shape_index1, shape_index2, contact.normal, contact.point_self, contact.point_other, contact.velocity_self, contact.velocity_other, contact.impulse); + if (jolt_body1->IsActive()) { + for (const Contact &contact : manifold.contacts1) { + body1->add_contact(body2, manifold.depth, shape_index1, shape_index2, contact.normal, contact.point_self, contact.point_other, contact.velocity_self, contact.velocity_other, contact.impulse); + } } - for (const Contact &contact : manifold.contacts2) { - body2->add_contact(body1, manifold.depth, shape_index2, shape_index1, contact.normal, contact.point_self, contact.point_other, contact.velocity_self, contact.velocity_other, contact.impulse); + if (jolt_body2->IsActive()) { + for (const Contact &contact : manifold.contacts2) { + body2->add_contact(body1, manifold.depth, shape_index2, shape_index1, contact.normal, contact.point_self, contact.point_other, contact.velocity_self, contact.velocity_other, contact.impulse); + } } manifold.contacts1.clear();