Skip to main content
New Participant
July 11, 2019

Modify OVRPointerVisualizer to only be visible when colliding with selectable objects

I don't really understand how OVRInputModule is handling the raycasts, but I just want the pointer to appear when I'm pointing at what I want to interact with.



I feel like I should be able to do something like the following, but I'm not getting anything happening. I'm sure what I should be exactly searching for in , but it seems like something that should be more commonplace.

 void Update() {
activeController = OVRInputHelpers.GetControllerForButton( OVRInput.Button.PrimaryIndexTrigger, activeController);
Ray selectionRay = OVRInputHelpers.GetSelectionRay( activeController, trackingSpace);

RaycastHit hit;
if (Physics.Raycast(selectionRay, out hit))
{
print("hit");
}

//if(selectionRay)
SetPointerVisibility();
SetPointer(selectionRay);
}

This topic has been closed for replies.

2 replies

Up and Coming
July 11, 2019
So i haven't looked at it in detail yet but i can give you two hints without doing so:

if(selectionRay) //this will always return true, since you set the Ray before
i know you commented it out, but i guess you either want to check for if(selectionHit != null)
or better
move the SetVisibility stuff into the brackets of the raycast check:
if (Physics.Raycast(selectionRay, out hit))
{

SetPointerVisibility();//does that take a bool? if so set it to true
SetPointer(selectionRay);


#if UNITY_EDITOR
  print("hit");//it's good use debug logs with
#if UNITY_EDITOR
 
#endif
}
Maybe you want to check the RascastHit, before setting anything or use a layerMask.
I think actually, you might profit from just making your own visualization bit that you have a 100% control over and that fits your game's aesthetics.

I don't know about your experience so if i say obvious things you did different for reasons i can't see, i apologize.

hope you got something out of it



guidewireAuthor
New Participant
July 12, 2019
Obviously I was in mid exploration of getting it to work.  I finally got something close to I want doing this instead.
void Update() {
activeController = OVRInputHelpers.GetControllerForButton( OVRInput.Button.PrimaryIndexTrigger, activeController);
Ray selectionRay = OVRInputHelpers.GetSelectionRay( activeController, trackingSpace);

RaycastHit hit;
//print("hit");

if (Physics.Raycast(selectionRay, out hit, 500f, mask ))
{
if(hit.collider != null)
{
print("hit " + hit.collider.name);
linePointer.enabled = true;
gazePointer.gameObject.SetActive(true);
//SetPointer(selectionRay, hit);
}
} else
{
linePointer.enabled = false;
gazePointer.gameObject.SetActive(false);
}


//if(selectionRay)
//SetPointerVisibility();
//SetPointer(selectionRay);
SetPointer(selectionRay, hit);
}