Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var wheelFL : Transform;
- var wheelFR : Transform;
- var wheelML : Transform;
- var wheelMR : Transform;
- var wheelBL : Transform;
- var wheelBR : Transform;
- //automatic transmission shift points
- var shiftDownRPM = 2500;
- var shiftUpRPM = 5500;
- //gear ratios
- var gearRatios = [-2.66, 2.66, 1.78, 1.30, 1.00];
- var finalDriveRatio = 3.4;
- var frontWheelSteering = false;
- var middleWheelSteering = false;
- var rearWheelSteering = false;
- var frontWheelDrive = false;
- var middleWheelDrive = false;
- var rearWheelDrive = false;
- var minSteeringAngle = 0.00;
- var maxSteeringAngle = 0.00;
- var highSpeed = 0.00;
- var motorMass = 1.00;
- var motorDrag = 0.00;
- var maxAcceleration = 0.00;
- var maxMotorSpeed = 0.00;
- var minTorque = 0.00;
- var maxTorque = 0.00;
- var centerOfMass : Vector3;
- rigidbody.centerOfMass = centerOfMass;
- private var queryUserInput = true;
- private var engineRPM : float;
- private var onGround = false;
- private var wheelRPM : float;
- private var gear = 1;
- private var scriptWheelFL : Wheel;
- private var scriptWheelFR : Wheel;
- private var scriptWheelML : Wheel;
- private var scriptWheelMR : Wheel;
- private var scriptWheelBL : Wheel;
- private var scriptWheelBR : Wheel;
- scriptWheelFL = wheelFL.GetComponent(Wheel);
- scriptWheelFR = wheelFR.GetComponent(Wheel);
- scriptWheelML = wheelML.GetComponent(Wheel);
- scriptWheelMR = wheelMR.GetComponent(Wheel);
- scriptWheelBL = wheelBL.GetComponent(Wheel);
- scriptWheelBR = wheelBR.GetComponent(Wheel);
- scriptWheelFL.car = this;
- scriptWheelFR.car = this;
- scriptWheelML.car = this;
- scriptWheelMR.car = this;
- scriptWheelBL.car = this;
- scriptWheelBR.car = this;
- var steeringInput = 0.00;
- var motorInput = 0.00;
- var motorTorque = 0.00;
- var motorAccel = 0.00;
- var motorSpeed = 0.00;
- var steeringAngle = 0.00;
- if(frontWheelDrive) scriptWheelFL.driven = scriptWheelFR.driven = true;
- if(middleWheelDrive) scriptWheelML.driven = scriptWheelMR.driven = true;
- if(rearWheelDrive) scriptWheelBL.driven = scriptWheelBR.driven = true;
- function FixedUpdate ()
- {
- steeringInput = Input.GetAxis("Horizontal");
- motorInput = Input.GetAxis("Vertical");
- if(frontWheelSteering) wheelFL.localRotation = wheelFR.localRotation = Quaternion.LookRotation(Vector3(steeringInput * (steeringAngle / 90), 0, 1 + (-1 * Mathf.Abs(steeringInput * (steeringAngle / 90))) ));
- if(middleWheelSteering) wheelML.localRotation = wheelMR.localRotation = Quaternion.LookRotation(Vector3(-steeringInput * (steeringAngle / 90), 0, 1 + (-1 * Mathf.Abs(steeringInput * (steeringAngle / 90))) ));
- if(rearWheelSteering) wheelBL.localRotation = wheelBR.localRotation = Quaternion.LookRotation(Vector3(-steeringInput * (steeringAngle / 90), 0, 1 + (-1 * Mathf.Abs(steeringInput * (steeringAngle / 90))) ));
- if(frontWheelDrive || middleWheelDrive || rearWheelDrive)
- {
- motorTorque = Mathf.Lerp(maxTorque / 30, minTorque / 30, motorSpeed / maxMotorSpeed) * Mathf.Abs(motorInput);
- if(motorTorque < 1) motorTorque = 1;
- motorAccel = Mathf.Lerp(maxAcceleration, 0, motorSpeed / maxMotorSpeed);
- steeringAngle = Mathf.Lerp(maxSteeringAngle, minSteeringAngle, rigidbody.velocity.magnitude / highSpeed);
- motorSpeed += motorInput * motorAccel / motorMass * Time.fixedDeltaTime;
- if(frontWheelDrive)
- {
- scriptWheelFL.speed = scriptWheelFR.speed = motorSpeed;
- }
- if(middleWheelDrive)
- {
- scriptWheelML.speed = scriptWheelMR.speed = motorSpeed;
- }
- if(rearWheelDrive)
- {
- scriptWheelBL.speed = scriptWheelBR.speed = motorSpeed;
- }
- motorSpeed += -motorSpeed * motorDrag / motorTorque * Time.fixedDeltaTime;
- }
- }
- //Automatically shift gears
- function AutomaticTransmission()
- {
- if(gear>0)
- {
- if(engineRPM>shiftUpRPM&&gear<gearRatios.length-1)
- gear++;
- if(engineRPM<shiftDownRPM&&gear>1)
- gear--;
- }
- }
- function AddForceOnMotor (force : float)
- {
- motorSpeed += force / motorTorque;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement