Conversation
| hit.rayDistance = | ||
| (static_cast<double>(allResults.m_hitFractions[i]) * maxDistance); | ||
| (static_cast<double>((allResults.m_hitFractions[i])) - scaledBuffer) * | ||
| totalLength / rayLength; |
There was a problem hiding this comment.
maybe cache totalLength / rayLength before the loop?
There was a problem hiding this comment.
Sure, could do. I feel like the math could be more elegant here, honestly, but I didn't come up with a better version so moving on for now. 😖
0mdc
left a comment
There was a problem hiding this comment.
LGTM overall. I would consider lowering the buffer distance.
| R"(Perform discrete collision detection for the scene. Physics must be enabled. Warning: may break simulation determinism.)") | ||
| .def( | ||
| "cast_ray", &Simulator::castRay, "ray"_a, "max_distance"_a = 100.0, | ||
| "buffer_distance"_a = 0.08, |
There was a problem hiding this comment.
Nit: 8cm is a pretty big distance for a buffer. Have you explored setting a lower value? (<=0.01 would be good).
There was a problem hiding this comment.
This value must be greater than the maximum expected collision margin (default is 4cm). I think 0.08 (8 cm) therefore is fine as we are ditching any hits within that distance anyway. FYI, the minimum I'd want to use is 4cm, so I doubled that.
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