Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhysicsDirectBodyState3D: report contact points using global coordinates #76088

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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