Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Anton's avatar
Anton
Honored Guest
13 years ago

Cursor Locking for First Person Games

Hi all,

As I've been playing around with integrating the OVRSDK into my first project, I ran into the situation that OnMouseDown/Up/Etc. are now fairly useless, as the cursor is in-between the two camera views, so it reporting the cursor position in a very un-intuitive/useless position. This ends up being a bit of a problem for almost anything using a cursor, as instead of using native functions, we're likely going to have to scratch-build an alternate solution (here's for hoping someone slams together an asset-store release for this quickly). From playing TF2 in vr mode, it seems they actually duplicate everything in both views, including the actual cursor itself.

Anyone have any quick hackee ideas for a generic cursor implementation?

2 Replies

Replies have been turned off for this discussion
  • owenwp's avatar
    owenwp
    Expert Protege
    The simplest way is to do a raycast into the scene from the camera position along the view direction and draw a screen oriented sprite object at the hit point as your cursor. You can have relative mouse movement shift the direction of that raycast as one possibility, or just lock it to the head orientation. Calling transform.forward on the head object will give you a vector pointing straight ahead, or you can use transform.localToWorldMatrix.MultiplyVector on a vector that you construct from mouse movement.
  • I think true 3D needs a truly 3D targeting mechanism. The reticle worked fine in 2D, but just doesn't work well in 3D. Actual ironsights is one way. Laser targeting (paint a laser target on the thing aimed at in each camera) is another.

    To determine what is being targeted, I'd raycast from the head (between the cameras) in the direction the cameras are looking.