Search Unity

Orbiting camera using touch controls

Discussion in 'AR/VR (XR) Discussion' started by neapolitanstudios, Feb 27, 2018.

  1. neapolitanstudios

    neapolitanstudios

    Joined:
    Feb 17, 2011
    Posts:
    75
    Hey all, I've been tackling this problem for the past few days, but I'm not really getting anywhere with it.

    I want to create a camera setup that orbits the player around an object in VR. You orbit around the object by holding your grip button on your touch control and dragging, and zoom in/out by holding the grips on both of your controllers and moving them closer/further apart. There are plenty of examples of this in games/apps:

    Google Blocks
    Oculus Medium
    Tethered (rotation gesture is a little different, but it's the same).

    It seems like a fairly standard practice in VR, but I can't find any good examples out there. Does anyone have any good examples of this being done in Unity? Or do you have any idea how this sort of thing can be implemented? I'm using Oculus Rift with touch controllers if that helps.

    Thanks!
     
  2. StickyHoneybuns

    StickyHoneybuns

    Joined:
    Jan 16, 2018
    Posts:
    207
    For orbiting your camera simply use Transform.RotateAround. Under your grip button press just add that.

    https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html

    Get the transform.position of each controller.
    Then using Vector3.Distance you store the value when both grips are pressed then compare to the previous value. So if the distance has increased you zoom in, if it has decreased, zoom out. Look here.

    https://docs.unity3d.com/ScriptReference/Vector3.Distance.html

    I have written a script like this for my VR app. Try to get somewhere with the two links and if you need specific help with the code just post back and ask.