Home > Enterprise >  How do I map continuous movement to oculus quest 2 controllers thumbstick?
How do I map continuous movement to oculus quest 2 controllers thumbstick?

Time:11-15

I am using the oculus integration toolkit. I was able to bind movement to my oculus quest 2 controller's thumbstick. I move right if I push the thumbstick right and move left if I push it to the left. However, the movement happens on each push, it's not continuous. I want the movement to continue while I'm still pushing the thumbstick right or left. How do I do this, please.

Here is my code.

 void Update()
    {
        if (OVRInput.GetUp(OVRInput.Button.PrimaryThumbstickRight))
        {
            gameObject.transform.Translate(Vector3.forward * speed * Time.deltaTime, Space.World);
        }
        
        if (OVRInput.GetUp(OVRInput.Button.PrimaryThumbstickLeft))
        {
            gameObject.transform.Translate(Vector3.back * speed * Time.deltaTime, Space.World);
        }
    }

CodePudding user response:

OVRInput.GetUp returns true when the button was released. It looks like you are asking when they stop pressing the thumbstick.

I would recommend using code like this:

// this gets the X and Y values of the thumbstick
vector2 input = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
// this moves the character based on how much the x axis is pressed.
// it's the same as your code, but it multiplies by the x axis instead
// of using a condition. doing this means you can also only partially
// push the joystick and you will only partially move.
gameObject.transform.Translate(Vector3.forward * speed * input.x * Time.deltaTime, Space.World);

If you don't want them to be able to partially press it to partially move, you can use your original code, but with input.x > 0.75f and input.x < -0.75f in the conditions instead.

I found this all here with a quick google search. Try to make sure google doesn't already know the answer before you ask.

  • Related