Hi there, I am struggling with my vehicle’s audio and I don’t know how to fix it? The audio pitch plays on 1 for a second then on 2 the next second going higher and higher. I want it to go smoothly up in the pitch. Any advice I will appreciate.
Here is my car controller script:
function Start () {
rigidbody.centerOfMass = Vector3(0, -0.05, 0);
mainCamera.camera.enabled = true;
topCamera.camera.enabled = false;
driverCamera.camera.enabled = false;
reverseCamera.camera.enabled = false;
}
function Update () {
speed = rigidbody.velocity.sqrMagnitude;
steer = -1 * Input.GetAxis("Rotate Player");
forward = Mathf.Clamp(Input.GetAxis("Move Forward"), 0, 1);
back = -1 * Mathf.Clamp(Input.GetAxis("Move Forward"), -1, 0);
if(speed == 0 && forward == 0 && back == 0) {
brakeRelease = true;
}
if(speed == 0 && brakeRelease) {
if(back > 0) { reverse = true; }
if(forward > 0) { reverse = false; }
}
//For Reversing
if(reverse) {
motor = 2 * back;
brake = forward;
ReverseLightObject.light.intensity = 0.0;
ReverseLightObject1.light.intensity = 0.0;
} else {
motor = forward * -2;
brake = back;
ReverseLightObject.light.intensity = 1.0;
ReverseLightObject1.light.intensity = 1.0;
}
if (brake > 0) {
//Brake lights
BackLightObject.light.intensity = 1.0;
BackLightObject1.light.intensity = 1.0;
brakeRelease = false; }
//Brake lights
else {
BackLightObject.light.intensity = 0.5;
BackLightObject1.light.intensity = 0.5;
}
frontWheel1.motorTorque = motor_max * motor;
frontWheel2.motorTorque = motor_max * motor;
rearWheel1.brakeTorque = brake_max * brake;
rearWheel2.brakeTorque = brake_max * brake;
FrontLeftWheel.steerAngle = Input.GetAxis("Rotate Player");
FrontRightWheel.steerAngle = Input.GetAxis("Rotate Player");
FrontSteer.steerAngle = 30 * Input.GetAxis("Rotate Player");
if(Input.GetButtonDown("Camera")) {
whichCamera ++;
changeView();
}
EngineSound();}
and the audio function:
function EngineSound() {
audio.pitch = speed/10+1;
}