All the ray-casting methods are indeed designed to only return first hit object. There are specific optimizations inside for this use-case, since it is the most common need.
To query everything, you can repeat the query, shifting RayOrigin
(position at which the ray starts) each time. This is similar to what I described in this post: Convenient way to determine exact point under mouse - #4 by michalis , albeit that was for a bit different task (to avoid detecting hits on transparent pixels).
So:
-
Use
MyViewport.CameraRayCollision(RayOrigin, RayDirection)
. It returnsTRayCollision
, just likeMouseRayHit
(so it can be processed in the same way as above to detect the particular point). It takes as input ray position and direction. -
Use it in a loop.
-
The initial
RayOrigin
,RayDirection
can come from the mouse position – useMyViewport.PositionToRay
. -
Make a call to
MyViewport.CameraRayCollision(RayOrigin, RayDirection)
. If something was hit, add it to the list, and make another call toMyViewport.CameraRayCollision(NewRayOrigin, RayDirection)
. TheNewRayOrigin
can be calculated like
NewRayOrigin := HitPosition + RayDirection.AdjustToLength(SomeEpsilon)
-