Skip to content

Commit

Permalink
Merge pull request #76088 from rburing/contact_points_global_3d
Browse files Browse the repository at this point in the history
PhysicsDirectBodyState3D: report contact points using global coordinates
  • Loading branch information
akien-mga authored May 10, 2023
2 parents 081808b + 15b8cb9 commit 769d8a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions doc/classes/PhysicsDirectBodyState2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<return type="Vector2" />
<param index="0" name="contact_idx" type="int" />
<description>
Returns the contact position in the collider.
Returns the position of the contact point on the collider in the global coordinate system.
</description>
</method>
<method name="get_contact_collider_shape" qualifiers="const">
Expand Down Expand Up @@ -169,7 +169,7 @@
<return type="Vector2" />
<param index="0" name="contact_idx" type="int" />
<description>
Returns the local position of the contact point.
Returns the position of the contact point on the body in the global coordinate system.
</description>
</method>
<method name="get_contact_local_shape" qualifiers="const">
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/PhysicsDirectBodyState3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<return type="Vector3" />
<param index="0" name="contact_idx" type="int" />
<description>
Returns the contact position in the collider.
Returns the position of the contact point on the collider in the global coordinate system.
</description>
</method>
<method name="get_contact_collider_shape" qualifiers="const">
Expand Down Expand Up @@ -169,7 +169,7 @@
<return type="Vector3" />
<param index="0" name="contact_idx" type="int" />
<description>
Returns the local position of the contact point.
Returns the position of the contact point on the body in the global coordinate system.
</description>
</method>
<method name="get_contact_local_shape" qualifiers="const">
Expand Down
8 changes: 4 additions & 4 deletions servers/physics_3d/godot_body_pair_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 769d8a7

Please sign in to comment.