unity-game-enginedaydream

How to get the distance from daydream controller to a pointed game object in unity?


Following the google-vr sample I manage to add a camera and controller to my scene. The next thing I need is to get the distance between my controller to any pointed game object in the scene. After searching for a while, I cannot find any tutorial nor information on how to get the distance.

So, is there any newest working tutorial on how to do this? (Many tutorial on the internet is outdated since google updates its API so frequently) Or it is actually a simple task i.e. I can get the value from GvrPointerInputModule.Pointer / GvrLaserPointer / some other GVR class? Thanks in advance~


Solution

  • Just as I suspected, GvrLaserPointer is the answer. If its CurrentRaycastResult.gameObject is not null, then the laser is intersecting with something. Then, we can get the intersection point from CurrentRaycastResult.worldPosition. Using this point, we can easily calculate the distance.

    Note: Just in case anyone failing with this method, like I did before. Check your ray casting group. Make sure that your Raycaster Event Mask in GVRPointerPhysicsRaycaster only include the desired layers. And if you have any canvas in screen space, check its Blocking Mask in Graphic Raycaster. It's Everything by default and your pointer may keep intersecting with the canvas, resulting in "weird" intersection point. This the cause of my problem, and to fix it, I select Nothing for Blocking Mask, and voila.