Forum Discussion

DemonGamesLab's avatar
6 years ago
Solved

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

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?
  • 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;
            }

        }

2 Replies

  • 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.
  • 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;
            }

        }