Skip to main content
New Participant
November 28, 2013

crosshair over objects

Hi all,

How can i detect if the crosshair is over a specific object from a scene?

I want to implement something like "look at an object and interact with it".

Thank you.
    This topic has been closed for replies.

    4 replies

    Inspiring
    November 28, 2013
    There's probably a lot of ways to solve this, but here's what I would do:
    • Add a collider to the object you want to look at/interact with (if it doesn't already have one).

    • Create a script where, in every Update(), you do a Physics.Raycast() from one of the Rift camera's transform.position (or even better, the midpoint between two two cameras) out along the direction of that camera's transform.forward, then check the resulting "hit info" to see if you hit that collider (or a different collider or nothing at all) and act accordingly.


    Hope that helps!
    Titans of Space PLUS for Quest is now available on DrashVR.com
    Up and Coming
    November 28, 2013
    "drash" wrote:
    There's probably a lot of ways to solve this, but here's what I would do:
    • Add a collider to the object you want to look at/interact with (if it doesn't already have one).

    • Create a script where, in every Update(), you do a Physics.Raycast() from one of the Rift camera's transform.position (or even better, the midpoint between two two cameras) out along the direction of that camera's transform.forward, then check the resulting "hit info" to see if you hit that collider (or a different collider or nothing at all) and act accordingly.


    Hope that helps!

    Yep that's one way of doing it. It may be advisable to do a spherecast, to make it a less strict test.
    Inspiring
    November 28, 2013
    "boone188" wrote:
    Yep that's one way of doing it. It may be advisable to do a spherecast, to make it a less strict test.


    TIL Spherecast! "Think of the sphere cast like a thick raycast." /unity docs.

    Awesome, thanks for the tip. :)
    Titans of Space PLUS for Quest is now available on DrashVR.com
    gskohnerAuthor
    New Participant
    December 2, 2013
    Thank you guys!