Skip to main content
Up and Coming
March 3, 2015

Unity mouse implementation

I am trying to implement Oculus into my game. For the life of me, I cannot find a good tutorial on implementing a mouse in Unity3d within VR. I need a mouse to be able to interact with a complex UI and the world environment. I can place the UI on a plane in front of the player no problem and it get it to show up as expected, but beyond that, I am lost on how to design and implement a good input scheme. Something similar to half life or Minecrift would work well for the game.

Thanks much!

    6 replies

    Inspiring
    March 4, 2015
    The cursor should be it's own object, that can be drawn in 3D space (not just plastered on the screen). The depth should be at the depth of the object it is on top of. Think of it as a laser pointer. You can do this with a ray cast from the center between the eyes into the scene. Hope that helps.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    StankiemAuthor
    Up and Coming
    March 4, 2015
    Thanks Cyber, surprised Oculus / another dev hasen't already made a good script for this on the asset store with keyhole and other configurable settings. Seems like there must be hundreds of people who have coded the same thing already.. :( But then again, maybe it's too specialized per application to really be that useful.
    Inspiring
    March 4, 2015
    Yes, this is something that I think would be very useful for developers.

    Maybe I'll see if I can hack something together as an example.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    March 6, 2015
    "cybereality" wrote:
    Yes, this is something that I think would be very useful for developers.

    Maybe I'll see if I can hack something together as an example.


    I hope you do!
    I'll buy it because it would be so useful.
    My attempts at raycasting are so intermittent and random!
    If it's below $50 I'll certainly be interested indeed.
    So please, if you can. :)
    StankiemAuthor
    Up and Coming
    March 10, 2015
    I just realized OVRCrosshair exists.. Hit "C" while using the OVRPlayerController and it brings up a crosshair with a keyhole etc... This is nice and has almost the exact behavior I want, a little tweaking will make it work very well. However... It's all a private class which leads me to believe that I would be able to access it's raytrace hit result somewhere? But it doesn't seem to even have a function to do this?

    Also, how would I use a solution like this with NGUI? I would need NGUI to recognize mouse clicks, drags, drops etc... Since it's only a raytrace interacting with the colliders and not the actual mouse, I don't think this will work.

    Sorry, searches have all come up dry on these topics.
    Participant
    March 24, 2015
    Just wanted to let you guys know that I did write a script package for this very problem, and it's available on the Unity Asset Store for $5. The cursor is a game object that has presence in the scene, and depending on the shape you choose for the 3D representation (it can be anything, just drop a prefab on the proper script variable) you can also determine the curve of a mesh. Kinda cool for rock climbing games and what not :)

    https://www.assetstore.unity3d.com/en/#!/content/11944

    Here's how to set it up in the latest Tuscany demo:
    https://www.youtube.com/watch?v=kOqoqB_RUfY