Search Unity

Question How to control the camera offset based on movements from the VR controller?

Discussion in 'XR Interaction Toolkit and Input' started by castana1962, Feb 6, 2021.

  1. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    400
    Hi Everyone,

    Now, we are starting to make our VR Health prototype ( we have a lot of work but we are very excited to do it !!)

    Our VR Game will be for people with disabilities for health problems (for example Parkinson, Stroke, etc), for that reason, we need to build it according to this pattern:

    walkinvrdriver.com/move-rotate-virtual-reality-disabled

    About this topic, I found out that primarily need to control the camera offset based on movements from the controller.

    Our goal is to build the same pattern amplifying the movements (up/down/ left/right) or bringing the place where the patient has to move through the controllers due to their poor mobility (for example, if the patient moves the VR controller 1 cm, the will move 10 cm in the game or bring the world towards him) to amplify the movements or move the around the Game Scene with that VR controllers without the patients has to move out of place.

    We will do it for Oculus Quest, and we are thinking of making it by XR Toolkit, for that reason, I would need if someone could help us with some example in Unity, to take it as a "reference" to make our Movement and Rotation for the patients.

    Would it be possible?

    Thanks for your time

    Best Regards

    Alejandro
     
  2. Simianosaurus

    Simianosaurus

    Joined:
    Feb 14, 2013
    Posts:
    14
    This should be simple with the XR Toolkit.

    If you wish to make them move based on the movement of a controller you just need to get the velocity of the controller and apply the inverse velocity to your character.

    The easiest way to do this is to give the player a CharacterController component, and ne movement script something like:

    Code (CSharp):
    1. public class PlayerControllerMovement : MonoBehaviour
    2. {
    3.     private CharacterController characterController;
    4.     public XRController inputController;
    5.  
    6.     void Start()
    7.     {
    8.         characterController  = GetComponent<CharacterController>();
    9.     }
    10.  
    11.     void FixedUpdate()
    12.     {
    13.         InputDevices.GetDeviceAtXRNode(inputController).TryGetFeatureValue(CommonUsages.deviceVelocity, out Vector3 velocity);
    14.         characterController.Move(-velocity * Time.fixedDeltaTime);
    15.     }
    16. }
    17.  
    If you need to scale the movement, then you can scale the velocity that you pass into the Move function.
     
    castana1962 likes this.
  3. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    400
    Hi Simianosaurus
    Sorry for the delay in my answer but I just to see your answer.
    Thanks for your help
    Best Regards
    Alejandro