W
W
Wadim_wadim20002020-05-07 17:06:09
C++ / C#
Wadim_wadim2000, 2020-05-07 17:06:09

Unity how to make the audiosourse pitch smoothly increase when moving, and also decrease when stopped?

The character (vehicle) moves like this:

void FixedUpdate()
{
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");
body.AddForce(transform.right * tankSpeed * v, ForceMode2D.Impulse);
body.AddTorque(tankRotationSpeed * h * -Mathf.Sign(v), ForceMode2D.Impulse);
}

audiosource is played when starting with pitch = 1
so how to make it smoothly increase pitch to 1.3 when it moves, and then also smoothly decrease to 1 when it stops?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wadim_wadim2000, 2020-05-08
@Wadim_wadim2000

Got it. I just found the numerical value of the speed (speed = body.velocity.magnitude) and got currentPith = defaultPitch + speed /100.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question