Search Unity

Using Vive controller to rotate an object

Discussion in 'AR/VR (XR) Discussion' started by SpiderJones, Nov 16, 2018.

  1. SpiderJones

    SpiderJones

    Joined:
    Mar 29, 2014
    Posts:
    244
    I'm trying to use the Vive controller to rotate an object. My approach is to have the controller enter/clip the object, then when the user pulls the trigger the object rotates as the player moves the controller. The object would rotate on an axis based on the direction the player is moving the controller.

    Does anyone have tips or suggestions?

    Thanks!
     
  2. MoMonay

    MoMonay

    Joined:
    May 9, 2018
    Posts:
    19
    The way I would probably approach this;

    "enter/clip the object and pull trigger": use a mesh collider, set it as OnTriggerEnter it should only collides with hands, in OnTriggerEnter function you set a bool variable such that ithe Update function will now check if the trigger on controller is being pressed.

    "The object rotates as the player moves the controller": in the Update function if the trigger is pressed, check if the position of the controller is saved, if not save it and exit the function, if so then check the new position against the old. You then calculate the difference in x,y,z and use those values to rotate the object based on those values (probably a fraction of those values).

    A similar approach has worked for me in the past.