Hello! Having a great time with the library, really well done.
I'm looking to implement a very primitive "is the body airborne" check by simply ray casting straight down, and if a hit occurs check whether the distance to the hit point is greater than some arbitrary value. Two questions there:
1. I see how the IHitHandler interface will provide the Collidable that was hit, but I don't see the actual Vector3 point of the hit. Is that available?
2. I'm assuming Simulation.Raycast reports all collidables that would be struck by the ray. For performance sake is there a way to call it as "report ONLY the closest hit, and then stop considering others" ?
Thanks much!
Raycasting hit point
Re: Raycasting hit point
IRayHitHandler.OnRayHit provides a 't' value which is how far along the ray the hit was. So, rayHitLocation = ray.Origin + ray.Direction * t. (It's not output directly because some intersection tests don't need to compute a hit location to figure out the t value; just a very minor optimization.)1. I see how the IHitHandler interface will provide the Collidable that was hit, but I don't see the actual Vector3 point of the hit. Is that available?
That sort of behavior is left up to the IRayHitHandler; note that the OnRayHit function passes the maximumT by reference, so it can be set. The OnRayHit callback is called from within the traversal, so modifying the maximumT means that future traversal or intersection tests will obey the new maximumT. Combined with the fact that the traversal visits the closer bounding box first, this turns out exactly equivalent to a 'first hit only' traversal.2. I'm assuming Simulation.Raycast reports all collidables that would be struck by the ray. For performance sake is there a way to call it as "report ONLY the closest hit, and then stop considering others" ?
In other words, in OnRayHit, set maximumT = t.
Re: Raycasting hit point
That's perfect, thanks! And for such a quick reply.
Re: Raycasting hit point
Also SUPER small thing: the in-code documentation for the t param is
I'm not familiar with those terms so it threw me for a bit of a loop - in case other folks aren't as well you could just add "(or the scalar distance down the ray from its origin to the hit point.)"
Thanks again!
Code: Select all
/// <param name="t">Hit time of the sweep test.</param>
Thanks again!