DemonGamesLab
6 years agoProtege
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;
}
}