Forum Discussion
gskohner
12 years agoHonored Guest
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.
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.
4 Replies
Replies have been turned off for this discussion
- drashHeroic ExplorerThere'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! - boone188Honored Guest
"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. - drashHeroic Explorer
"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. :) - gskohnerHonored GuestThank you guys!
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 1 year ago
- 3 years ago