Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

How to get the information from Oculus touch analogue in C#

DemonGamesStudioDemonGamesStudio Posts: 24 Oculus Start Member
I am trying to figure out how to get the information from the analogue so I can register footstep sounds by the amount of which the player is moving. I don't want the steps to be inconsistent so I want the sounds to slow down or speed up depending how much the player is moving the analogue. I have no idea on how to write the code for this. Can anyone point me in the right direction?

Best Answer

  • DemonGamesStudioDemonGamesStudio Posts: 24 Oculus Start Member
    Accepted Answer
    I managed to figure it out by using the character controller and velocity for anyone with future issues like this here is the full script I used.

    CharacterController controller;
        public AudioClip SnowFootstep;
        public AudioSource audsrc;

        private float footstepsCounter = 0;
        private float stepFrequency = 0.8f;

        void Start() {
            controller = this.GetComponent<CharacterController>();
        }

        void Update() {
            Vector3 horizontalVelocity = controller.velocity;
            horizontalVelocity = new Vector3(controller.velocity.x, 0, controller.velocity.z);

            // The speed on the x-z plane ignoring any speed
            float horizontalSpeed = horizontalVelocity.magnitude;
            // The speed from gravity or jumping
            float verticalSpeed = controller.velocity.y;
            // The overall speed
            float overallSpeed = controller.velocity.magnitude;


            footstepsCounter += Time.deltaTime * horizontalSpeed;
            if (footstepsCounter >= stepFrequency) {
                audsrc.pitch = Random.Range(0.7f, 2.1f);
                audsrc.clip = SnowFootstep;
                audsrc.PlayOneShot(SnowFootstep);
                footstepsCounter = 0;
            }

        }

Answers

  • WeitinWeitin Posts: 32
    Brain Burst
    If you're talking about the joystick, you can get its position by:
    OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.RTouch);
    As for speeding up/down the audio, you can set the pitch of your AudioSource based on the magnitude of the vector.
    Wei Tin Yuen, VR Developer  B)
    Toronto, Canada
    http://tinforge.com/
Sign In or Register to comment.