Skip to content

Commit

Permalink
Merge pull request #42637 from madmiraal/fix-infinite-inertia-3.2
Browse files Browse the repository at this point in the history
[3.x] Apply infinite inertia checks to Godot physics 3D
  • Loading branch information
akien-mga authored Jun 11, 2021
2 parents caaac22 + 01dd6b0 commit fed44e3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions servers/physics/space_sw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,13 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve
const CollisionObjectSW *col_obj = intersection_query_results[i];
int shape_idx = intersection_query_subindex_results[i];

if (CollisionObjectSW::TYPE_BODY == col_obj->get_type()) {
const BodySW *b = static_cast<const BodySW *>(col_obj);
if (p_infinite_inertia && PhysicsServer::BODY_MODE_STATIC != b->get_mode() && PhysicsServer::BODY_MODE_KINEMATIC != b->get_mode()) {
continue;
}
}

if (CollisionSolverSW::solve_static(body_shape, body_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), cbkres, cbkptr, nullptr, p_margin)) {
collided = cbk.amount > 0;
}
Expand Down Expand Up @@ -865,6 +872,13 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve
const CollisionObjectSW *col_obj = intersection_query_results[i];
int shape_idx = intersection_query_subindex_results[i];

if (CollisionObjectSW::TYPE_BODY == col_obj->get_type()) {
const BodySW *b = static_cast<const BodySW *>(col_obj);
if (p_infinite_inertia && PhysicsServer::BODY_MODE_STATIC != b->get_mode() && PhysicsServer::BODY_MODE_KINEMATIC != b->get_mode()) {
continue;
}
}

//test initial overlap, does it collide if going all the way?
Vector3 point_A, point_B;
Vector3 sep_axis = motion_normal;
Expand Down Expand Up @@ -971,6 +985,13 @@ bool SpaceSW::test_body_motion(BodySW *p_body, const Transform &p_from, const Ve
const CollisionObjectSW *col_obj = intersection_query_results[i];
int shape_idx = intersection_query_subindex_results[i];

if (CollisionObjectSW::TYPE_BODY == col_obj->get_type()) {
const BodySW *b = static_cast<const BodySW *>(col_obj);
if (p_infinite_inertia && PhysicsServer::BODY_MODE_STATIC != b->get_mode() && PhysicsServer::BODY_MODE_KINEMATIC != b->get_mode()) {
continue;
}
}

rcd.object = col_obj;
rcd.shape = shape_idx;
rcd.local_shape = j;
Expand Down

0 comments on commit fed44e3

Please sign in to comment.