Grabble Hands in VR ( Ray Interactor ) - Unity3d

 



In a previous post, we used a sphere collider to detect if the object is close enough to grab. Another method we can use is using a Ray Interactor. Ray Interactor uses a line (visible or invisible) to detect if the object is within reach.

XR Ray Interactor


Within the XR Ray Interactor, we'll just be looking into the Raycast Configuration. For this flashlight, we don't want anything fancy so we'll keep the line type as a straight line instead of a curve line, and we can adjust the max raycast distance accordingly. Default it's set to 30 but in the future, we'll change the ray cast so that it can only grab objects much closer. For the other 3 options, we'll keep it the way it is as we're only using it to grab items.

Line Renderer and XR Interactor Line Visual



The line renderer's job is to render the line so that it's visible while the XR Interactor Line Visual details how the line looks. We can see some options such as color and gradient and also an override line length so that we don't need to make sure the XR Ray Interactor and the Visual line are desyncs. We also will keep the stop line at the first raycast hit so that it doesn't go through numerous objects. With these settings, we can visualize the line and grab objects that the line points to.