Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

NullReferenceException: Object reference not set to an instance of an object Vehicle Controls.

$
0
0
This error has been bugging me... I know its probably a simple solution but I just cant see it :'( NullReferenceException: Object reference not set to an instance of an object Vehicle Controls.Start () (at Assets/Scripts/Vehicle Controls.js:84) Its on this line for(var i: int =1; i<16; ++i) { CarSound.Add(GameObject.Find(String.Format("CarSound ([])",i)).GetComponent.()); CarSound[i-1].Play(); } Heres the full script #pragma strict import System.Collections.Generic; var wheelFL : WheelCollider; var wheelFR : WheelCollider; var wheelRL : WheelCollider; var wheelRR : WheelCollider; var wheelFLTrans : Transform; var wheelFRTrans : Transform; var wheelRLTrans : Transform; var wheelRRTrans : Transform; var maxHP : float = 1560; var currentSpeed : float; var topSpeed : float = 420; var engineRPM: float; var currentGear: int; var torque: float; var gearUpRPM: float; var gearDownRPM: float; var gearRatio: float[]; var brakeTorque: int; var kph : float; var kphDisplay : UI.Text; var mph : float; var mphDisplay : UI.Text; var lowestSteerSpeed : float = 260; var lowSpeedSteerAngle : float = 20; var highSpeedSteerAngle : float = 10; var decelerationSpeed : float = 30; var maxReverseSpeed : float = 10; var backLightObeject : GameObject; var idleLightMaterial : Material; var brakeLightMaterial : Material; var reverseLightMaterial : Material; private var braked : boolean = false; var maxBrakeTorque : float = 100; private var MySidewaysFriction : float; private var MyForwardFriction : float; private var slipForwardFriction : float; private var slipSidewaysFriction : float; private var Range : float; private var ReducedRPM : float; private var PitchMath : float; var steerAngle; var MinRpmTable : float[] = [50.0f, 75.0 , 112.0 , 166.9 , 222.4 , 278.3 , 333.5 , 388.2 , 435.5 , 483.3 , 538.4 , 594.3 , 643.6 , 692.8 , 741.9 , 790.0 ]; var NormalRpmTable : float[] = [72.0 , 93.0 , 155.9 , 202.8 , 267.0 , 314.5 , 377.4 , 423.9 , 472.1 , 519.4 , 582.3 , 631.3 , 680.8 , 729.4 , 778.8 , 826.1 ]; var MaxRpmTable : float[] = [92.0 , 136.0 , 182.9 , 247.4 , 294.3 , 357.5 , 403.6 , 452.5 , 499.3 , 562.5 , 612.3 , 661.6 , 708.8 , 758.9 , 806.0 , 1000.0 ]; var PitchingTable : float[] = [0.12 , 0.12 , 0.12 , 0.12 , 0.11 , 0.10 , 0.09 , 0.08 , 0.06 , 0.06 , 0.06 , 0.06 , 0.06 , 0.06 , 0.06 , 0.06 ]; var RangeDivider : float = 4f; var soundRPM : float; var CarSound :List.; function Start () { GetComponent.().centerOfMass.y = -0.04; GetComponent.().centerOfMass.z = 0.02; setValues(); for(var i: int =1; i<16; ++i) { CarSound.Add(GameObject.Find(String.Format("CarSound ([])",i)).GetComponent.()); CarSound[i-1].Play(); } } function setValues () { MyForwardFriction = wheelRR.forwardFriction.stiffness; MySidewaysFriction= wheelRR.sidewaysFriction.stiffness; slipForwardFriction = 0.04; slipSidewaysFriction = 0.01; } function FixedUpdate () { Control (); BackLight (); wheelPosition (); HandBrake (); EngineSound (); AutoGears(); engineRPM = Mathf.Round((wheelRL.rpm * gearRatio[currentGear])); soundRPM = Mathf.Round(engineRPM * (1000 / 420)); torque = maxHP * gearRatio[currentGear]; } function Update () { wheelFLTrans.Rotate(wheelFL.rpm/60*-360*Time.deltaTime,0,0); wheelFRTrans.Rotate(wheelFR.rpm/60*-360*Time.deltaTime,0,0); wheelRRTrans.Rotate(wheelRR.rpm/60*360*Time.deltaTime,0,0); wheelRLTrans.Rotate(wheelRL.rpm/60*360*Time.deltaTime,0,0); wheelFLTrans.localEulerAngles.y = wheelFL.steerAngle - wheelFLTrans.localEulerAngles.z; wheelFRTrans.localEulerAngles.y = wheelFR.steerAngle - wheelFRTrans.localEulerAngles.z + 180; } function Control () { currentSpeed = 2*22/7*wheelRL.radius*wheelRL.rpm*60/100000; currentSpeed = Mathf.Round(currentSpeed); kph = GetComponent.().velocity.magnitude * 3.6f; kph = Mathf.RoundToInt(kph); kphDisplay.text = kph + " KPH"; mph = GetComponent.().velocity.magnitude * 2.237f; mph = Mathf.RoundToInt(mph); mphDisplay.text = mph + " MPH"; if (currentSpeed < topSpeed && currentSpeed > maxReverseSpeed && !braked && engineRPM <= gearUpRPM){ wheelRR.motorTorque = maxHP * Input.GetAxis("Vertical")*15; wheelRL.motorTorque = maxHP * Input.GetAxis("Vertical")*15; } else { wheelRR.motorTorque = 0; wheelRL.motorTorque = 0; } if (Input.GetButton ("Vertical")== false){ wheelRR.brakeTorque = decelerationSpeed; wheelRL.brakeTorque = decelerationSpeed; } else { wheelRR.brakeTorque = 0; wheelRL.brakeTorque = 0; } if (engineRPM > 0 && Input.GetAxis("Vertical") < 0 && engineRPM <= gearUpRPM) { wheelRL.brakeTorque = brakeTorque; wheelRR.brakeTorque = brakeTorque; } else { wheelRL.brakeTorque = 0; wheelRR.brakeTorque = 0; } //rear wheel drive car var speedFactor = GetComponent.().velocity.magnitude/lowestSteerSpeed; var currentSteerAngle = Mathf.Lerp(lowSpeedSteerAngle,highSpeedSteerAngle,speedFactor); currentSteerAngle *= Input.GetAxis("Horizontal"); wheelFL.steerAngle = currentSteerAngle; wheelFR.steerAngle = currentSteerAngle; } function AutoGears(){ var AppropriateGear: int = currentGear; if (engineRPM >= gearUpRPM){ for (var i = 0; i < gearRatio.Length; i++){ if (wheelRL.rpm * gearRatio[i] < gearUpRPM){ AppropriateGear = i; break; } } currentGear = AppropriateGear; } if (engineRPM <= gearDownRPM){ AppropriateGear = currentGear; for (var j = gearRatio.Length - 1; j >= 0; j--){ if (wheelRL.rpm * gearRatio[j] > gearDownRPM){ AppropriateGear = j; break; } } currentGear = AppropriateGear; } } function BackLight () { if (currentSpeed > 0 && Input.GetAxis("Vertical")<0 &&!braked){ backLightObeject.GetComponent.().material = brakeLightMaterial; } else if (currentSpeed < 0 && Input.GetAxis("Vertical")>0&&!braked) { backLightObeject.GetComponent.().material = brakeLightMaterial; } else if (currentSpeed < 0 && Input.GetAxis("Vertical")<0&&!braked){ backLightObeject.GetComponent.().material = reverseLightMaterial; } else if (!braked){ backLightObeject.GetComponent.().material = idleLightMaterial; } } function wheelPosition () { var hit : RaycastHit; var wheelPos : Vector3; //wheelFL if (Physics.Raycast(wheelFL.transform.position, - wheelFL.transform.forward,hit,wheelFL.radius+wheelFL.suspensionDistance)) { wheelPos = hit.point+wheelFL.transform.forward * wheelFL.radius; } else { wheelPos = wheelFL.transform.position -wheelFL.transform.forward * wheelFL.suspensionDistance; } wheelFLTrans.position = wheelPos; //wheel FR if (Physics.Raycast(wheelFR.transform.position, - wheelFR.transform.forward,hit,wheelFR.radius+wheelFR.suspensionDistance)) { wheelPos = hit.point+wheelFR.transform.forward * wheelFR.radius; } else { wheelPos = wheelFR.transform.position -wheelFR.transform.forward * wheelFR.suspensionDistance; } wheelFRTrans.position = wheelPos; // wheelRR if (Physics.Raycast(wheelRR.transform.position, - wheelRR.transform.forward,hit,wheelRR.radius+wheelRR.suspensionDistance)) { wheelPos = hit.point+wheelRR.transform.forward * wheelRR.radius; } else { wheelPos = wheelRR.transform.position -wheelRR.transform.forward * wheelRR.suspensionDistance; } wheelRRTrans.position = wheelPos; // wheelRL if (Physics.Raycast(wheelRL.transform.position, - wheelRL.transform.forward,hit,wheelRL.radius+wheelRL.suspensionDistance)) { wheelPos = hit.point+wheelRL.transform.forward * wheelRL.radius; } else { wheelPos = wheelRL.transform.position -wheelRL.transform.forward * wheelRL.suspensionDistance; } wheelRLTrans.position = wheelPos; } function HandBrake () { if(Input.GetButton ("Jump")) { braked = true; } else { braked = false; } if (braked) { wheelFR.brakeTorque = maxBrakeTorque; wheelFL .brakeTorque = maxBrakeTorque; wheelRR.motorTorque = 0; wheelRL.motorTorque = 0; if (GetComponent.().velocity.magnitude >1){ SetSlip(slipForwardFriction,slipSidewaysFriction); } else { SetSlip(1 , 1); } if (currentSpeed < 1 && currentSpeed > - 1) { backLightObeject.GetComponent.().material = idleLightMaterial; } else { backLightObeject.GetComponent.().material = brakeLightMaterial; } } else{ wheelFR.brakeTorque = 0; wheelFL .brakeTorque = 0; SetSlip(MyForwardFriction , MySidewaysFriction); } } function SetSlip (currentForwardFriction : float,currentSidewaysFriction : float){ wheelRR.forwardFriction.stiffness = currentForwardFriction; wheelRL.forwardFriction.stiffness = currentForwardFriction; //wheelFR.forwardFriction.stiffness = currentForwardFriction; //wheelFL.forwardFriction.stiffness = currentForwardFriction; wheelRR.sidewaysFriction.stiffness = currentSidewaysFriction; wheelRL.sidewaysFriction.stiffness = currentSidewaysFriction; //wheelFL.sidewaysFriction.stiffness = currentSidewaysFriction; //wheelFR.sidewaysFriction.stiffness = currentSidewaysFriction; } function EngineSound () { for (var i: int = 0; i < 16; i++) { if (i == 0) { //Set CarSound[0] if (MinRpmTable[i] > soundRPM) { CarSound[0].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[0].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[0].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[0].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[0].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[0].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[0].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 1) { //Set CarSound[1] if (MinRpmTable[i] > soundRPM) { CarSound[1].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[1].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[1].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[1].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[1].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[1].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[0].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 2) { //Set CarSound[2] if (MinRpmTable[i] > soundRPM) { CarSound[2].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[2].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[2].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[2].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[2].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[2].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[2].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 3) { //Set CarSound[3] if (MinRpmTable[i] > soundRPM) { CarSound[3].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[3].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[3].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[3].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[3].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[3].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[3].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 4) { //Set CarSound[4] if (MinRpmTable[i] > soundRPM) { CarSound[4].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[4].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[4].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[4].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[4].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[4].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[4].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 5) { //Set CarSound[5] if (MinRpmTable[i] > soundRPM) { CarSound[5].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[5].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[5].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[5].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[5].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[5].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[5].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 6) { //Set CarSound[6] if (MinRpmTable[i] > soundRPM) { CarSound[6].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[6].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[6].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[6].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[6].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[6].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[6].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 7) { //Set CarSound[7] if (MinRpmTable[i] > soundRPM) { CarSound[7].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[7].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[7].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[7].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[7].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[7].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[7].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 8) { //Set CarSound[8] if (MinRpmTable[i] > soundRPM) { CarSound[8].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[8].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[8].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[8].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[8].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[8].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[8].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 9) { //Set CarSound[9] if (MinRpmTable[i] > soundRPM) { CarSound[9].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[9].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[9].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[9].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[9].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[9].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[9].pitch = 1f + PitchingTable[i] + PitchMath; } }else if (i == 10) { //Set CarSound[10] if (MinRpmTable[i] > soundRPM) { CarSound[10].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[10].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[10].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[10].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[10].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[10].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[10].pitch = 1f + PitchingTable[i] + PitchMath; } } else if (i == 11) { //Set CarSound[11] if (MinRpmTable[i] > soundRPM) { CarSound[11].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[11].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[11].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[11].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[11].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[11].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[11].pitch = 1f + PitchingTable[i] + PitchMath; } }else if (i == 12) { //Set CarSound[12] if (MinRpmTable[i] > soundRPM) { CarSound[12].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[12].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[12].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[12].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[12].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[12].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[12].pitch = 1f + PitchingTable[i] + PitchMath; } }else if (i == 13) { //Set CarSound[13] if (MinRpmTable[i] > soundRPM) { CarSound[13].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[13].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[13].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[13].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[13].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[13].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[13].pitch = 1f + PitchingTable[i] + PitchMath; } }else if (i == 14) { //Set CarSound[14] if (MinRpmTable[i] > soundRPM) { CarSound[14].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[14].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[14].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[14].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[14].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[14].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[14].pitch = 1f + PitchingTable[i] + PitchMath; } }else if (i == 15) { //Set CarSound[15] if (MinRpmTable[i] > soundRPM) { CarSound[15].volume = 0.0; } else if (soundRPM >= MinRpmTable[i] && soundRPM < NormalRpmTable[i]) { Range = NormalRpmTable[i] - MinRpmTable[i]; ReducedRPM = soundRPM - MinRpmTable[i]; CarSound[15].volume = ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[15].pitch = 1 - PitchingTable[i] + PitchMath; } else if (soundRPM >= NormalRpmTable[i] && soundRPM <= MaxRpmTable[i]) { Range = MaxRpmTable[i] - NormalRpmTable[i]; ReducedRPM = soundRPM - NormalRpmTable[i]; CarSound[15].volume = 1; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; CarSound[15].pitch = 1 + PitchMath; } else if (soundRPM > MaxRpmTable[i]) { Range = (MaxRpmTable[i + 1] - MaxRpmTable[i]) / RangeDivider; ReducedRPM = soundRPM - MaxRpmTable[i]; CarSound[15].volume = 1 - ReducedRPM / Range; PitchMath = (ReducedRPM * PitchingTable[i]) / Range; //CarSound[15].pitch = 1f + PitchingTable[i] + PitchMath; } } } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>