Skip to content

Commit

Permalink
Merge pull request #43924 from madmiraal/fix-43588-3.2
Browse files Browse the repository at this point in the history
[3.2] Fix cast_motion sometimes failing
  • Loading branch information
akien-mga authored Jan 14, 2021
2 parents d8ad9b2 + 2e99b5b commit 152415a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions doc/classes/Physics2DDirectSpaceState.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<argument index="0" name="shape" type="Physics2DShapeQueryParameters">
</argument>
<description>
Checks how far the shape can travel toward a point. If the shape can not move, the array will be empty.
[b]Note:[/b] Both the shape and the motion are supplied through a [Physics2DShapeQueryParameters] object. The method will return an array with two floats between 0 and 1, both representing a fraction of [code]motion[/code]. The first is how far the shape can move without triggering a collision, and the second is the point at which a collision will occur. If no collision is detected, the returned array will be [code][1, 1][/code].
Checks how far a [Shape2D] can move without colliding. All the parameters for the query, including the shape and the motion, are supplied through a [Physics2DShapeQueryParameters] object.
Returns an array with the safe and unsafe proportions (between 0 and 1) of the motion. The safe proportion is the maximum fraction of the motion that can be made without a collision. The unsafe proportion is the minimum fraction of the distance that must be moved for a collision. If no collision is detected a result of [code][1.0, 1.0][/code] will be returned.
[b]Note:[/b] Any [Shape2D]s that the shape is already colliding with e.g. inside of, will be ignored. Use [method collide_shape] to determine the [Shape2D]s that the shape is already colliding with.
</description>
</method>
<method name="collide_shape">
Expand Down
5 changes: 3 additions & 2 deletions doc/classes/PhysicsDirectSpaceState.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
<argument index="1" name="motion" type="Vector3">
</argument>
<description>
Checks whether the shape can travel to a point. The method will return an array with two floats between 0 and 1, both representing a fraction of [code]motion[/code]. The first is how far the shape can move without triggering a collision, and the second is the point at which a collision will occur. If no collision is detected, the returned array will be [code][1, 1][/code].
If the shape can not move, the returned array will be [code][0, 0][/code] under Bullet, and empty under GodotPhysics.
Checks how far a [Shape] can move without colliding. All the parameters for the query, including the shape, are supplied through a [PhysicsShapeQueryParameters] object.
Returns an array with the safe and unsafe proportions (between 0 and 1) of the motion. The safe proportion is the maximum fraction of the motion that can be made without a collision. The unsafe proportion is the minimum fraction of the distance that must be moved for a collision. If no collision is detected a result of [code][1.0, 1.0][/code] will be returned.
[b]Note:[/b] Any [Shape]s that the shape is already colliding with e.g. inside of, will be ignored. Use [method collide_shape] to determine the [Shape]s that the shape is already colliding with.
</description>
</method>
<method name="collide_shape">
Expand Down
4 changes: 3 additions & 1 deletion modules/bullet/space_bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf
bt_xform_to.getOrigin() += bt_motion;

if ((bt_xform_to.getOrigin() - bt_xform_from.getOrigin()).fuzzyZero()) {
r_closest_safe = 1.0f;
r_closest_unsafe = 1.0f;
bulletdelete(btShape);
return false;
return true;
}

GodotClosestConvexResultCallback btResult(bt_xform_from.getOrigin(), bt_xform_to.getOrigin(), &p_exclude, p_collide_with_bodies, p_collide_with_areas);
Expand Down
4 changes: 2 additions & 2 deletions servers/physics/space_sw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform
continue;
}

//test initial overlap
//test initial overlap, ignore objects it's inside of.
sep_axis = p_motion.normalized();

if (!CollisionSolverSW::solve_distance(shape, p_xform, col_obj->get_shape(shape_idx), col_obj_xform, point_A, point_B, aabb, &sep_axis)) {
return false;
continue;
}

//just do kinematic solving
Expand Down
4 changes: 2 additions & 2 deletions servers/physics_2d/space_2d_sw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transfor
continue;
}

//test initial overlap
//test initial overlap, ignore objects it's inside of.
if (CollisionSolver2DSW::solve(shape, p_xform, Vector2(), col_obj->get_shape(shape_idx), col_obj_xform, Vector2(), NULL, NULL, NULL, p_margin)) {

return false;
continue;
}

//just do kinematic solving
Expand Down

0 comments on commit 152415a

Please sign in to comment.