- Home /
Question by
Mannfred · Feb 26, 2013 at 12:50 PM ·
audioaudio sourcecarspitch
Car Audio Pitch
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;
}
Comment
Answer by Shadow-Rider · Jun 08, 2015 at 08:45 AM
I Hope i Got your problem..U don't have any gear function...if u had a gear function u can solve that using this Code: audio.pitch=((Speed - gearMinValue)/ (gearMaxValue - gearMinValue)) + 1;
Like For Gear 1 limit speed: 0-30,then for 2nd one 30-60...just like that...
Your answer
![](https://koobas.hobune.stream/wayback/20220613093434im_/https://answers.unity.com/themes/thub/images/avi.jpg)