This PR fixes a long-standing raycasting bug related to the behavior of Bullet physics raycasting within the collision margin of a convex shape.
TL;DR: we add a hidden "buffer distance" to the raycast to avoid missing an object from within its margin.
Context:
Bullet physics raycasts do not register hits from within convex shapes, neither entering, nor exiting.
Each collision shape has a configurable margin distance which is used to pad the collision detection algorithm to better catch upcoming impacts between dynamic shapes and avoid discrete collision issues near boundaries.
(a) Raycasts against convex shapes hit the shape, not the margin.
(b) Raycast origins within the margin are not considered.
Taken together, (a) and (b) result in a narrow region of space near the surface of an object where a raycast will not register the object it is about to hit, though expecting a positive hit distance from the API. This "null" zone causes a number of bugs as we attempt to snap objects onto each other or detect which objects are resting upon others.
Solution:
The simple solution is to back-pad the raycast origins and then re-scale the resulting distances such that rays cast within the margin still hit the shape as expected while any hits between the buffer and origin are discarded.
How Has This Been Tested
CI raycast tests still pass as before with expected global hit points and distances, despite the buffer.
Added new unit tests to specifically target this bug and demonstrate the solution.
Motivation and Context
This PR fixes a long-standing raycasting bug related to the behavior of Bullet physics raycasting within the collision margin of a convex shape.
TL;DR: we add a hidden "buffer distance" to the raycast to avoid missing an object from within its margin.
Context:
Solution:
How Has This Been Tested
CI raycast tests still pass as before with expected global hit points and distances, despite the buffer. Added new unit tests to specifically target this bug and demonstrate the solution.
Types of changes
Checklist