Car sound with respect to speed
I need my car sound pitch to be changed with respect to speed. Current i am using the solution of an answer which is :https://answers.unity.com/questions/1067016/car-engine-sound-code-unity5car-engine-sound-code.html
public float topSpeed = 100; // km per hour
private float currentSpeed = 0;
private float pitch = 0;
void Update () {
currentSpeed = transform.GetComponent
<Rigidbody>
().velocity.magnitude * 3.6f;
pitch = currentSpeed / topSpeed;
transform.GetComponent <AudioSource>
().Pitch = pitch;
}
As per this the starting pitch is 0 And it changes as per my current speed I.e - current speed/topspeed so when my current speed = top speed the pitch will be 1 and it's good approach But in my case it plays the sound but when once my car reaches top speed it stops playing sound than and Nevers plays it again even if I brake and start from zero speed
As I am an beginner intermediate i think it's because of my rigidbody of car is kinematic but I don't know the correct reason and any solution of this
Any kind of help will be appreciated
Can you debug.log your speed and make you your currentSpeed is not higher than topspeed never?
Yes I checked that too $$anonymous$$y current speed never crosses my top speed