From 15b8cb9d9c6814fe12f1d9c2f5e359957ac09a1a Mon Sep 17 00:00:00 2001 From: Ricardo Buring Date: Sat, 15 Apr 2023 14:29:01 +0200 Subject: [PATCH] PhysicsDirectBodyState3D: report contact points using global coordinates Also update the documentation to reflect this in both 2D and 3D. --- doc/classes/PhysicsDirectBodyState2D.xml | 4 ++-- doc/classes/PhysicsDirectBodyState3D.xml | 4 ++-- servers/physics_3d/godot_body_pair_3d.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/classes/PhysicsDirectBodyState2D.xml b/doc/classes/PhysicsDirectBodyState2D.xml index 0716d71bae80..d35fd5b9c561 100644 --- a/doc/classes/PhysicsDirectBodyState2D.xml +++ b/doc/classes/PhysicsDirectBodyState2D.xml @@ -127,7 +127,7 @@ - Returns the contact position in the collider. + Returns the position of the contact point on the collider in the global coordinate system. @@ -169,7 +169,7 @@ - Returns the local position of the contact point. + Returns the position of the contact point on the body in the global coordinate system. diff --git a/doc/classes/PhysicsDirectBodyState3D.xml b/doc/classes/PhysicsDirectBodyState3D.xml index def9ca7a5031..77ebd58ad971 100644 --- a/doc/classes/PhysicsDirectBodyState3D.xml +++ b/doc/classes/PhysicsDirectBodyState3D.xml @@ -127,7 +127,7 @@ - Returns the contact position in the collider. + Returns the position of the contact point on the collider in the global coordinate system. @@ -169,7 +169,7 @@ - Returns the local position of the contact point. + Returns the position of the contact point on the body in the global coordinate system. diff --git a/servers/physics_3d/godot_body_pair_3d.cpp b/servers/physics_3d/godot_body_pair_3d.cpp index c467a583ba0d..acd3547c536d 100644 --- a/servers/physics_3d/godot_body_pair_3d.cpp +++ b/servers/physics_3d/godot_body_pair_3d.cpp @@ -354,6 +354,8 @@ bool GodotBodyPair3D::pre_solve(real_t p_step) { bool do_process = false; + const Vector3 &offset_A = A->get_transform().get_origin(); + const Basis &basis_A = A->get_transform().basis; const Basis &basis_B = B->get_transform().basis; @@ -382,7 +384,6 @@ bool GodotBodyPair3D::pre_solve(real_t p_step) { #ifdef DEBUG_ENABLED if (space->is_debugging_contacts()) { - const Vector3 &offset_A = A->get_transform().get_origin(); space->add_debug_contact(global_A + offset_A); space->add_debug_contact(global_B + offset_A); } @@ -410,14 +411,13 @@ bool GodotBodyPair3D::pre_solve(real_t p_step) { if (A->can_report_contacts() || B->can_report_contacts()) { Vector3 crB = B->get_angular_velocity().cross(c.rB) + B->get_linear_velocity(); Vector3 crA = A->get_angular_velocity().cross(c.rA) + A->get_linear_velocity(); - Vector3 wlB = global_B - offset_B; if (A->can_report_contacts()) { - A->add_contact(global_A, -c.normal, depth, shape_A, crA, wlB, shape_B, B->get_instance_id(), B->get_self(), crB, c.acc_impulse); + A->add_contact(global_A + offset_A, -c.normal, depth, shape_A, crA, global_B + offset_A, shape_B, B->get_instance_id(), B->get_self(), crB, c.acc_impulse); } if (B->can_report_contacts()) { - B->add_contact(wlB, c.normal, depth, shape_B, crB, global_A, shape_A, A->get_instance_id(), A->get_self(), crA, -c.acc_impulse); + B->add_contact(global_B + offset_A, c.normal, depth, shape_B, crB, global_A + offset_A, shape_A, A->get_instance_id(), A->get_self(), crA, -c.acc_impulse); } }