Search Unity

Realistic Car Kit - [Released]

Discussion in 'Assets and Asset Store' started by 3dpowermax, Jun 4, 2014.

  1. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    Realistic Car Kit is a new package which is designed for Car Games that would give you the ability to work
    and hand it easily. This package include two different cars which allows you to
    select the car you’d like to use . ;)





    Features of this package :
    * Damage feature included sound and real car damage feature
    * Cameras are all set fine and The views can be easily changed and shifted
    * Car controls are all real that would give you the real sense of driving
    * This package is easily manipulated and edited
    * Brake lines and particles are perfectly used in this package
    * The car include shifting system

    contact info:
    3dpowermax@gmail.com


    Instructions

    Demo-WebPlayer


    Link in Asset Store:
    https://www.assetstore.unity3d.com/en/#!/content/18421





    * i test it on android and it's works very well...(you can download "apk" file test)



    APK File (Test):
    https://db.tt/vRmpBcgo

    regards
     
    Last edited: Jun 8, 2014
  2. PlaymintDev

    PlaymintDev

    Joined:
    Jan 11, 2014
    Posts:
    328
    This is essentially Vcar v2.0, which I've already paid for, but you've somehow managed to get it removed from the asset store, therefore wasting my money and time with the package.

    I'm not about to fork out more money again for a separate package for what was already an existing product, but renamed ( even if there 'is' updates to it ).

    Overall, I'm fairly annoyed, and slightly disappointed in your strategy with this, now I'm the owner of a defunct unitypackage. :(

     
    3dpowermax and quantumsheep like this.
  3. quantumsheep

    quantumsheep

    Joined:
    Mar 9, 2013
    Posts:
    37
    Yeah, I noticed this too - I was looking for Vcar and noticed it was missing. Today I found this.

    To the OP - I don't want to sound too negative as I haven't bought this or your previous asset, but I've been put off by this behaviour. I just don't see the point of you doing things like this, and it doesn't exactly give me confidence in buying from you.

    A shame, as the demos were fun!

    Sorry!

    QS
     
    3dpowermax likes this.
  4. ctknoxville

    ctknoxville

    Joined:
    Oct 1, 2013
    Posts:
    32
    Does it work with mobile. Have touch controls?
     
    3dpowermax likes this.
  5. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    Hey guys..
    Thanks for your comments and responses ..
    Well the previous one was removed by asset store for some reasons ..
    we have put a lot of efforts to bring back the assets .. sorry for any inconvenience
    If you have bought it before you must send us (private massage) the invoice numbers and receipt so we could figure out the validity

    It's not added to the asset but it's possible to add such feature

    thanks.
     
    Last edited: Jun 4, 2014
  6. PlaymintDev

    PlaymintDev

    Joined:
    Jan 11, 2014
    Posts:
    328
    As an update, I contacted 3dPowerMax with my previous invoice number for VCar, and after confirmation, was passed a link with the updated asset, the process was fairly quick and easy.

    Regards
     
    3dpowermax likes this.
  7. cl9

    cl9

    Joined:
    May 31, 2013
    Posts:
    417
    Will you be able to add simple racing AI (with vehicle avoidance)?
     
    3dpowermax likes this.
  8. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    ok my friend i add it as soon in here...
     
  9. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    Hi guys...
    i test it on android and it's works very well...(you can download "apk" file test)



    APK File (Test):
    https://db.tt/vRmpBcgo

    regards
     
  10. ctknoxville

    ctknoxville

    Joined:
    Oct 1, 2013
    Posts:
    32
    Looks good. Can you add the Android sample source to the asset or give us a way to download the project to see how you set this up?
     
    3dpowermax likes this.
  11. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    thanks
    you can make it very easy with "EasyTouch" asset for android or IOS...
     
  12. cl9

    cl9

    Joined:
    May 31, 2013
    Posts:
    417
    Have you made any progress with the AI integration? Earlier this year, you had demonstration videos.
     
  13. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    Simple AI Racing with RCK

     
    cl9 likes this.
  14. cl9

    cl9

    Joined:
    May 31, 2013
    Posts:
    417
    Do the AI cars have vehicle avoidance?
    At some points, the AI cars appear to be hitting other cars.
     
  15. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    no its not avoidance its very simple and i make it in 2 days ;)
    actually its need more work for better result ...
     
  16. cl9

    cl9

    Joined:
    May 31, 2013
    Posts:
    417
    Any progress or updates to the asset? Has the AI proven difficult for you to implement?
     
  17. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    24
    When the cars stopped, slide on the ground
     
    Stephan-Tanguay likes this.
  18. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    24
    any solution for this?
     
    Stephan-Tanguay likes this.
  19. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    hi
    as soon i add some things in the package such as AI , mobile control ...
    thanks

    hi
    Where and when this happens?
    thanks
     
  20. Ajay_kumar

    Ajay_kumar

    Joined:
    Aug 1, 2014
    Posts:
    2
  21. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    411
    I wish you would not waste time on developing AI, and just spend more time on the physics and making the code run even faster - performance.

    Anyone who expects car racing AI for under $200 is a bit silly, you should set it aside

    Your MSK motorbike kit is FANTASTIC programming, very impressive. RCK is amazing at the price. It compares favourably to Edy's, which is great but much more heavyweight.
     
  22. cl9

    cl9

    Joined:
    May 31, 2013
    Posts:
    417
    IRDS costs $150. Very positive reviews.
    RGK starts at $50.

    The author has also given no indication of what he's working on at the moment.
     
  23. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    339
    Police car does that in it's own scene. Do you have a solution for this?
     
  24. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    Hi,
    i check it ,
    The problem is the street.and I'll fix it as soon .
    thanks
     
    Stephan-Tanguay likes this.
  25. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    339
    Another question is, I find documentation is very poor. What the numbers in gears mean? How can I achieve a realistic transmission range. Car accelerates very slow at first, after 10km/h it bumps the speed to 130 km/h and this all happens just in gear 1 .
     
  26. suraj_1990

    suraj_1990

    Joined:
    Feb 26, 2015
    Posts:
    3
    Hi,

    I am Using this plugin in my Trailer Truck, I use Rigidbody.useGravity and Hinge Joint connected to the Trailer. Trailer behave abnormal when I start moving (Trailer is floating). How to overcome from this issue.

    looking forward for your suggestions, I am newbie to unity.

    Thanks
     
    Last edited: Mar 12, 2015
  27. SpaceRay

    SpaceRay

    Joined:
    Feb 26, 2014
    Posts:
    393
    Hello, I have bought this asset today, but I wonder why this thread has not be updated since March 2015?, and we are now in January 2016, and there has been a updated version of this asset in January 2016.

    I think that the driving and controlling of the car is one of the best I have seen on the asset store, and I have tested other 3 car controllers available, and I prefer this one above the others, because:

    * it has fast reactions and is easy to control and drive it
    * reaches high speed easily
    * can drift and turn fast but in a controlled way and can do it very easy without need to use the brake, just turn the wheel, even at high speed.
    * the brakes reacts well and in time
    * It has a good damage system for deformable impact meshes
    * goes perfectly straight when going forward (something not done well on others)
    * when turning the car is does it correctly and smoothly
    * it has very good mobile controllers, some none of the other has
    * has nitro speed optionally
    * is well done the back button to brake and then if still pressed go backward
    * The third person follow camera works very well and always is making that the car is always seen going forward even if you crash, the camera turns also
    * it has a very good first person camera view from a very good and realistic interior of the car
    * and another additional great more closer first person camera from directly outside on the front of the car.
    * The vehicle physics are good and well done realistically
    * Good brake and backward lights
    * It has a way to change the engine sound according the gears change
    * it uses 3 different sounds for the car engine that it makes a more realistic sound
    * and more additional good things I like

    The only negative thing is that is not 100% compatible with Unity 5.3 where you get some red errors that will not stop you from using play, But it will not allow to build a scene to be exported in build settings.

    Although it works very well and without any error on Unity 5.2.3


    Thanks
     
    Last edited: Aug 6, 2017
    3dpowermax likes this.
  28. mentolatux

    mentolatux

    Joined:
    Nov 2, 2014
    Posts:
    236
    i have an questions , i want to add 2 more wheels to move right and left and not working , please help !
     

    Attached Files:

    3dpowermax likes this.
  29. 3dpowermax

    3dpowermax

    Joined:
    Sep 9, 2013
    Posts:
    110
    Hi,
    actually this kit designed for 4 wheel cars but you can edit the script for extra wheels ,
    contact info : 3dpowermax@gmail.com
    thanks
     
  30. mentolatux

    mentolatux

    Joined:
    Nov 2, 2014
    Posts:
    236
    for thats why i write on forum to show me in script where to i need to duplicate code for extra wheels, im not coder so edit script and send me here with 2 more wheels please
    Code (CSharp):
    1. //----------------------------------------------
    2. //            Realistic Car Controller
    3. //
    4. // Copyright © 2015 BoneCracker Games
    5. // http://www.bonecrackergames.com
    6. //
    7. //----------------------------------------------
    8.  
    9. #pragma warning disable 0414
    10.  
    11. using UnityEngine;
    12. using UnityEngine.Audio;
    13. using System;
    14. using System.Collections;
    15. using System.Collections.Generic;
    16. using UnityEngine.UI;
    17. using UnityEngine.EventSystems;
    18.  
    19. [RequireComponent (typeof(Rigidbody))]
    20. public class RCCCarControllerV2 : MonoBehaviour {
    21.  
    22.     private Rigidbody rigid;        // Rigidbody.
    23.     internal bool sleepingRigid = false;        // Used For Disabling Unnecessary Raycasts When RB Is Sleeping.
    24.  
    25.     // Mobile Controller.
    26.     public bool mobileController = false;
    27.     public MobileGUIType _mobileControllerType;
    28.     public enum MobileGUIType{UIController, NGUIController}
    29.  
    30.     public bool AIController = false;        // Use AI Controller.
    31.    
    32.     // Dashboard Type.
    33.     public bool dashBoard = false;
    34.     public DashboardType _dashboardType;
    35.     public enum DashboardType{UIDashboard, NGUIDashboard}
    36.    
    37.     public bool useAccelerometerForSteer = false, steeringWheelControl = false;        // Use Accelerometer Or Steering Wheel Controlling For Mobile Use.
    38.     public float gyroTiltMultiplier = 2f;        // Gyro Sensitivity.
    39.    
    40.     public bool demoGUI = false;        // Display Information GUI.
    41.     public bool showMobileControllerChangerButtons = false;        // Display Mobile Controller Changer Buttons GUI.
    42.     private Vector3 defbrakePedalPosition;        // Caching Default Brake Pedal Position In Case Of Using Accelerometer.
    43.     public bool autoFindButtons = true;        // Finds all buttons when new vehicle spawned. Useful for spawning new vehicles on your scene at runtime.
    44.    
    45.     // NGUI Controller Elements.
    46.     public RCCNGUIController gasPedalNGUI, brakePedalNGUI, leftArrowNGUI, rightArrowNGUI, handbrakeNGUI, boostNGUI;        // If boost UI is selected, will multiply default engine torque by 2.5.
    47.     // UI Controller Elements.
    48.     public RCCUIController gasPedalUI, brakePedalUI, leftArrowUI, rightArrowUI, handbrakeUI, boostUI;        // If boost UI is selected, will multiply default engine torque by 2.5.
    49.    
    50.     // Wheel Transforms Of The Vehicle.
    51.     public Transform FrontLeftWheelTransform;
    52.     public Transform FrontRightWheelTransform;
    53.     public Transform RearLeftWheelTransform;
    54.     public Transform RearRightWheelTransform;
    55.    
    56.     // Wheel Colliders Of The Vehicle.
    57.     public WheelCollider FrontLeftWheelCollider;
    58.     public WheelCollider FrontRightWheelCollider;
    59.     public WheelCollider RearLeftWheelCollider;
    60.     public WheelCollider RearRightWheelCollider;
    61.  
    62.     // All Wheel Colliders.
    63.     [HideInInspector]public WheelCollider[] allWheelColliders;
    64.  
    65.     // Wheel Friction Curves.
    66.     private WheelFrictionCurve sidewaysFriction;
    67.     private WheelFrictionCurve forwardFriction;
    68.    
    69.     // Extra Wheels. In case of if your vehicle has extra wheels.
    70.     public Transform[] ExtraRearWheelsTransform;
    71.     public WheelCollider[] ExtraRearWheelsCollider;
    72.    
    73.     public bool applyEngineTorqueToExtraRearWheelColliders = true;        //Applies Engine Torque To Extra Rear Wheels.
    74.  
    75.     public Transform SteeringWheel;        // Driver Steering Wheel. In case of if your vehicle has individual steering wheel model in interior.
    76.    
    77.     // Set wheel drive of the vehicle. If you are using rwd, you have to be careful with your rear wheel collider
    78.     // settings and com of the vehicle. Otherwise, vehicle will behave like a toy.
    79.     public WheelType _wheelTypeChoise = WheelType.RWD;
    80.     public enum WheelType{FWD, RWD, AWD, DRIFT}
    81.    
    82.     //Center of mass.
    83.     public Transform COM;
    84.    
    85.     public bool canControl = true;        // Enables/Disables controlling the vehicle.
    86.     public bool runEngineAtAwake = true;        // Engine Running At Awake?
    87.     public bool canEngineStall = true;        // Engine Stalls If Engine RPM Is Lower Then Minimum Engine RPM / 2.
    88.     public bool engineRunning = false;        // Engine Running Now?
    89.     public bool autoReverse = true;        // Enables/Disables auto reversing when player press brake button. Useful for if you are making parking style game.
    90.     public bool automaticGear = true;        // Enables/Disables automatic gear shifting of the vehicle.
    91.     private bool canGoReverseNow = false;
    92.    
    93.     public AnimationCurve[] engineTorqueCurve;        // Each Gear Ratio Curves Generated By Editor Script.
    94.     public float[] gearSpeed;        // Target Speed For Changing Gear.
    95.     public float engineTorque = 3000f;        // Default Engine Torque.
    96.     public float maxEngineRPM = 7000f;        // Maximum Engine RPM.
    97.     public float minEngineRPM = 1000f;        // Minimum Engine RPM.
    98.    
    99.     public float steerAngle = 40f;        // Maximum Steer Angle Of Your Vehicle.
    100.     public float highspeedsteerAngle = 10f;        // Maximum Steer Angle At Highest Speed.
    101.     public float highspeedsteerAngleAtspeed = 80f;        // Highest Speed For Maximum Steer Angle.
    102.     public float antiRoll = 5000f;        // Anti Roll Force For Preventing Flip Overs And Stability.
    103.  
    104.     //Downforce.
    105.     public float downForce = 25f;        // Applies Downforce Releated With Vehicle Speed.
    106.  
    107.     public float speed;        // Vehicle Speed as KM/H.
    108.     public float brake = 4000f;        // Maximum Brake Torque.
    109.     public float maxspeed = 220f;        //Maximum Speed.
    110.  
    111.     private float resetTime = 0f;
    112.     private float defSteerAngle = 0f;
    113.    
    114.     // Gears.
    115.     public int currentGear;        // Current Gear Of The Vehicle.
    116.     public int totalGears = 6;            // Total Gears Of The Vehicle.
    117.     [Range(0f, .5f)]public float gearShiftingDelay = .35f;
    118.     public bool changingGear = false;        // Changing Gear Currently.
    119.     public bool reverseGear = false;        // Reverse Gear Currently.
    120.  
    121.     public bool autoGenerateGearCurves = true;
    122.     public bool autoGenerateTargetSpeedsForChangingGear = true;
    123.    
    124.     // Each Wheel Transform's Rotation Value.
    125.     private float _rotationValueFL, _rotationValueFR, _rotationValueRL, _rotationValueRR;
    126.     private float[] _rotationValueExtra;
    127.    
    128.     // Private Bools.
    129.     private float acceleration = 0f;
    130.     private float lastVelocity = 0f;
    131.     private bool engineStarting = false;
    132.    
    133.     //AudioSources and AudioClips.
    134.     private AudioSource engineStartSound;
    135.     public AudioClip engineStartClip;
    136.     private AudioSource engineSoundOn;
    137.     public AudioClip engineClipOn;
    138.     private AudioSource engineSoundOff;
    139.     public AudioClip engineClipOff;
    140.     private AudioSource gearShiftingSound;
    141.     public AudioClip[] gearShiftingClips;
    142.     private AudioSource crashSound;
    143.     public AudioClip[] crashClips;
    144.     private AudioSource windSound;
    145.     public AudioClip windClip;
    146.     private AudioSource brakeSound;
    147.     public AudioClip brakeClip;
    148.     private AudioSource skidSound;
    149.     public AudioClip asphaltSkidClip;
    150.     public AudioClip grassSkidClip;
    151.     public AudioClip sandSkidClip;
    152.  
    153.     [Range(.25f, 1f)]public float minEngineSoundPitch = .75f;
    154.     [Range(1.25f, 2f)]public float maxEngineSoundPitch = 1.75f;
    155.     [Range(0f, 1f)]public float minEngineSoundVolume = .05f;
    156.     [Range(0f, 1f)]public float maxEngineSoundVolume = .85f;
    157.  
    158.     [Range(0f, 1f)]public float maxGearShiftingSoundVolume = .3f;
    159.     [Range(0f, 1f)]public float maxSkidSoundVolume = 1f;
    160.     [Range(0f, 1f)]public float maxCrashSoundVolume = 1f;
    161.     [Range(0f, 1f)]public float maxWindSoundVolume = .25f;
    162.     [Range(0f, 1f)]public float maxBrakeSoundVolume = .2f;
    163.  
    164.     [HideInInspector]public GameObject allAudioSources;
    165.     private GameObject allContactParticles;
    166.  
    167.     // Physic Materials.
    168.     public PhysicMaterial asphaltPhysicsMaterial;
    169.     public PhysicMaterial grassPhysicsMaterial;
    170.     public PhysicMaterial sandPhysicsMaterial;
    171.     public PhysicMaterial terrainPhysicsMaterial;
    172.  
    173.     // Use Terrain SplatMap For Various Ground Physics.
    174.     public bool UseTerrainSplatMapForGroundPhysics = false;
    175.  
    176.     public int terrainSplatMapAsphaltIndex;
    177.     public int terrainSplatMapGrassIndex;
    178.     public int terrainSplatMapSandIndex;
    179.    
    180.     // Inputs.
    181.     [HideInInspector]public float gasInput = 0f;
    182.     [HideInInspector]public float brakeInput = 0f;
    183.     [HideInInspector]public float steerInput = 0f;
    184.     [HideInInspector]public float clutchInput = 0f;
    185.     [HideInInspector]public float handbrakeInput = 0f;
    186.     [HideInInspector]public float fuelInput = 1f;
    187.     [HideInInspector]public float boostInput = 1f;
    188.  
    189.     private float engineRPM = 0f;        // Actual Engine RPM.
    190.     private float wheelRPMToSpeed = 0f;        // Converted Wheel RPM To Speed.
    191.    
    192.     // UI DashBoard.
    193.     public RCCDashboardInputs UIInputs;
    194.     private RectTransform RPMNeedle;
    195.     private RectTransform KMHNeedle;
    196.  
    197.     // NGUI Dashboard.
    198.     public GameObject RPMNeedleNGUI;
    199.     public GameObject KMHNeedleNGUI;
    200.  
    201.     private float RPMNeedleRotation = 0f;
    202.     private float KMHNeedleRotation = 0f;
    203.     private float smoothedNeedleRotation = 0f;
    204.    
    205.     // Smokes.
    206.     public GroundMaterial _groundMaterial = GroundMaterial.Asphalt;
    207.     public enum GroundMaterial{Asphalt, Grass, Sand}
    208.    
    209.     public GameObject wheelSlipAsphalt;
    210.     public GameObject wheelSlipSand;
    211.     private List <ParticleSystem> _wheelSlipAsphalt = new List<ParticleSystem>();
    212.     private List <ParticleSystem> _wheelSlipSand = new List<ParticleSystem>();
    213.  
    214.     // Exhaust Gasses.
    215.     public ParticleSystem[] exhaustGas;
    216.    
    217.     public GameObject chassis;        // Script Will Simulate Chassis Movement Based On Vehicle Rigidbody Velocity.
    218.     public float chassisVerticalLean = 4.0f;        // Chassis Vertical Lean Sensitivity.
    219.     public float chassisHorizontalLean = 4.0f;        // Chassis Horizontal Lean Sensitivity.
    220.     private float horizontalLean = 0.0f;
    221.     private float verticalLean = 0.0f;
    222.    
    223.     // Lights.
    224.     public Light[] headLights;
    225.     public Light[] brakeLights;
    226.     public Light[] reverseLights;
    227.     public bool headLightsOn = false;
    228.     private float brakeLightInput;
    229.  
    230.     // Damage.
    231.     public bool useDamage = true;
    232.     struct originalMeshVerts{public Vector3[] meshVerts;}
    233.     public MeshFilter[] deformableMeshFilters;
    234.     public float randomizeVertices = 1f;
    235.     public float damageRadius = .5f;
    236.    
    237.     private float minimumVertDistanceForDamagedMesh = .002f;        // Comparing Original Vertex Positions Between Last Vertex Positions To Decide Mesh Is Repaired Or Not.
    238.    
    239.     private Vector3[] colliderVerts;
    240.     private originalMeshVerts[] originalMeshData;
    241.     [HideInInspector]public bool sleep = true;
    242.    
    243.     public float maximumDamage = .5f;        // Maximum Vert Distance For Limiting Damage. 0 Value Will Disable The Limit.
    244.     private float minimumCollisionForce = 5f;
    245.     public float damageMultiplier = 1f;
    246.    
    247.     public GameObject contactSparkle;
    248.     public int maximumContactSparkle = 5;
    249.     private List<ParticleSystem> contactSparkeList = new List<ParticleSystem>();
    250.     public bool repairNow = false;
    251.    
    252.     private Vector3 localVector;
    253.     private Quaternion rot = Quaternion.identity;
    254.  
    255.     //Steering Helper.
    256.     [Range(0f, 1f)] public float steerHelper = .1f;
    257.     private float oldRotation;
    258.  
    259.     //Driving Assistances.
    260.     public bool ABS = true;
    261.     public bool TCS = true;
    262.     public bool ESP = true;
    263.     public bool steeringHelper = true;
    264.    
    265.     public bool ABSAct = false;
    266.     public bool TCSAct = false;
    267.     public bool ESPAct = false;
    268.    
    269.     [Range(.05f, .5f)]public float ABSThreshold = .35f;
    270.     [Range(.05f, .5f)]public float TCSThreshold = .25f;
    271.     [Range(0f, 1f)]public float TCSStrength = 1f;
    272.     [Range(.05f, .5f)]public float ESPThreshold = .25f;
    273.     [Range(.1f, 1f)]public float ESPStrength = .5f;
    274.  
    275.     // Drift Variables
    276.     internal float driftAngle = 0f;
    277.     private bool driftingNow = false;
    278.     public bool applyCounterSteering = false;
    279.  
    280.     //Steering Wheel.
    281.     public GameObject steeringWheelGameObject;
    282.     public Image steeringWheelTexture;  
    283.     public float steeringWheelAngle = 0f;
    284.     public float steeringWheelMaximumsteerAngle = 270f;
    285.     public float steeringWheelResetPosSpeed = 10f;  
    286.     public float steeringWheelCenterDeadZoneRadius = 5f;
    287.     public float steeringWheelDefaultAlpha = .5f, steeringWheelActiveAlpha = 1f;
    288.     public bool steeringWheelInteractable = true;
    289.    
    290.     private RectTransform steeringWheelRect;
    291.     private CanvasGroup steeringWheelCanvasGroup;
    292.     private float steeringWheelTempAngle, steeringWheelNewAngle;
    293.     private bool steeringWheelPressed;
    294.     private Vector2 steeringWheelCenter, steeringWheelTouchPos;
    295.  
    296.     private EventTrigger eventTrigger;
    297.    
    298.     void Awake() {
    299.  
    300.         if(!GetComponent<RCCAICarController>())
    301.             AIController = false;
    302.        
    303.     }
    304.  
    305.     void Start (){
    306.  
    307.         rigid = GetComponent<Rigidbody>();
    308.         rigid.maxAngularVelocity = 12f;
    309.         Time.fixedDeltaTime = .02f;
    310.  
    311.         allWheelColliders = GetComponentsInChildren<WheelCollider>();
    312.         WheelCollider anyWheel = GetComponentInChildren<WheelCollider>();
    313.         anyWheel.ConfigureVehicleSubsteps(30f, 20, 20);
    314.         _rotationValueExtra = new float[ExtraRearWheelsCollider.Length];
    315.         defSteerAngle = steerAngle;
    316.  
    317.         allAudioSources = new GameObject("All Audio Sources");
    318.         allAudioSources.transform.SetParent(transform);
    319.         allAudioSources.transform.localPosition = Vector3.zero;
    320.         allAudioSources.transform.localRotation = Quaternion.identity;
    321.  
    322.         allContactParticles = new GameObject("All Contact Particles");
    323.         allContactParticles.transform.SetParent(transform);
    324.         allContactParticles.transform.localPosition = Vector3.zero;
    325.         allContactParticles.transform.localRotation = Quaternion.identity;
    326.  
    327.         if(dashBoard && GameObject.FindObjectOfType<RCCDashboardInputs>()){
    328.  
    329.             UIInputs = GameObject.FindObjectOfType<RCCDashboardInputs>();
    330.             UIInputs.GetNeedles();
    331.  
    332.             if(_dashboardType == DashboardType.NGUIDashboard){
    333.                 RPMNeedleNGUI = UIInputs.RPMNeedleNGUI;
    334.                 KMHNeedleNGUI = UIInputs.KMHNeedleNGUI;
    335.             }else{
    336.                 RPMNeedle = UIInputs.RPMNeedleUI;
    337.                 KMHNeedle = UIInputs.KMHNeedleUI;
    338.             }
    339.            
    340.         }else if(dashBoard){
    341.  
    342.             //Debug.LogError("RCCDashboardInputs not found! Ensure your scene has UI or NGUI canvas with RCCDashboardInputs script. You can use ready to use prefabs in Prefabs folder.");
    343.             dashBoard = false;
    344.  
    345.         }
    346.  
    347.         if(autoFindButtons && mobileController){
    348.  
    349.             RCCMobileButtons UIButtons = GameObject.FindObjectOfType<RCCMobileButtons>();
    350.  
    351.             if(_mobileControllerType == MobileGUIType.NGUIController){
    352.                 gasPedalNGUI = UIButtons.gasButton.GetComponent<RCCNGUIController>();
    353.                 brakePedalNGUI = UIButtons.brakeButton.GetComponent<RCCNGUIController>();
    354.                 leftArrowNGUI = UIButtons.leftButton.GetComponent<RCCNGUIController>();
    355.                 rightArrowNGUI = UIButtons.rightButton.GetComponent<RCCNGUIController>();
    356.                 if(UIButtons.handbrakeButton)
    357.                     handbrakeNGUI = UIButtons.handbrakeButton.GetComponent<RCCNGUIController>();
    358.                 if(UIButtons.boostButton)
    359.                     boostNGUI = UIButtons.boostButton.GetComponent<RCCNGUIController>();
    360.             }else{
    361.                 gasPedalUI = UIButtons.gasButton.GetComponent<RCCUIController>();
    362.                 brakePedalUI = UIButtons.brakeButton.GetComponent<RCCUIController>();
    363.                 leftArrowUI = UIButtons.leftButton.GetComponent<RCCUIController>();
    364.                 rightArrowUI = UIButtons.rightButton.GetComponent<RCCUIController>();
    365.                 if(UIButtons.handbrakeButton)
    366.                     handbrakeUI = UIButtons.handbrakeButton.GetComponent<RCCUIController>();
    367.                 if(UIButtons.boostButton)
    368.                     boostUI = UIButtons.boostButton.GetComponent<RCCUIController>();
    369.             }
    370.  
    371.             if(UIButtons.steeringWheel)
    372.                 steeringWheelTexture = UIButtons.steeringWheel.GetComponent<Image>();
    373.  
    374.         }
    375.  
    376.         SoundsInitialize();
    377.         MobileGUI();
    378.         SmokeInit();
    379.  
    380.         if(useDamage)
    381.             DamageInit();
    382.  
    383.         if(runEngineAtAwake)
    384.             KillOrStartEngine();
    385.        
    386.     }
    387.    
    388.     public void CreateWheelColliders (){
    389.        
    390.         List <Transform> allWheelTransforms = new List<Transform>();
    391.         allWheelTransforms.Add(FrontLeftWheelTransform); allWheelTransforms.Add(FrontRightWheelTransform); allWheelTransforms.Add(RearLeftWheelTransform); allWheelTransforms.Add(RearRightWheelTransform);
    392.        
    393.         if(allWheelTransforms[0] == null){
    394.             Debug.LogError("You haven't choose your Wheel Transforms. Please select all of your Wheel Transforms before creating Wheel Colliders. Script needs to know their positions, aye?");
    395.             return;
    396.         }
    397.        
    398.         transform.rotation = Quaternion.identity;
    399.        
    400.         GameObject WheelColliders = new GameObject("Wheel Colliders");
    401.         WheelColliders.transform.SetParent(transform);
    402.         WheelColliders.transform.localRotation = Quaternion.identity;
    403.         WheelColliders.transform.localPosition = Vector3.zero;
    404.         WheelColliders.transform.localScale = Vector3.one;
    405.        
    406.         foreach(Transform wheel in allWheelTransforms){
    407.            
    408.             GameObject wheelcollider = new GameObject(wheel.transform.name);
    409.            
    410.             wheelcollider.transform.position = wheel.transform.position;
    411.             wheelcollider.transform.rotation = transform.rotation;
    412.             wheelcollider.transform.name = wheel.transform.name;
    413.             wheelcollider.transform.SetParent(WheelColliders.transform);
    414.             wheelcollider.transform.localScale = Vector3.one;
    415.             wheelcollider.AddComponent<WheelCollider>();
    416.             wheelcollider.GetComponent<WheelCollider>().radius = (wheel.GetComponent<MeshRenderer>().bounds.extents.y) / transform.localScale.y;
    417.  
    418.             wheelcollider.AddComponent<RCCWheelCollider>();
    419.            
    420.             JointSpring spring = wheelcollider.GetComponent<WheelCollider>().suspensionSpring;
    421.  
    422.             spring.spring = 35000f;
    423.             spring.damper = 1500f;
    424.  
    425.             wheelcollider.GetComponent<WheelCollider>().suspensionSpring = spring;
    426.             wheelcollider.GetComponent<WheelCollider>().suspensionDistance = .2f;
    427.             wheelcollider.GetComponent<WheelCollider>().forceAppPointDistance = .15f;
    428.             wheelcollider.GetComponent<WheelCollider>().mass = 125f;
    429.             wheelcollider.GetComponent<WheelCollider>().wheelDampingRate = 1f;
    430.            
    431.             sidewaysFriction = wheelcollider.GetComponent<WheelCollider>().sidewaysFriction;
    432.             forwardFriction = wheelcollider.GetComponent<WheelCollider>().forwardFriction;
    433.  
    434.             forwardFriction.extremumSlip = .4f;
    435.             forwardFriction.extremumValue = 1;
    436.             forwardFriction.asymptoteSlip = .8f;
    437.             forwardFriction.asymptoteValue = .75f;
    438.             forwardFriction.stiffness = 1f;
    439.  
    440.             sidewaysFriction.extremumSlip = .25f;
    441.             sidewaysFriction.extremumValue = 1;
    442.             sidewaysFriction.asymptoteSlip = .5f;
    443.             sidewaysFriction.asymptoteValue = .75f;
    444.             sidewaysFriction.stiffness = 1f;
    445.  
    446.             wheelcollider.GetComponent<WheelCollider>().sidewaysFriction = sidewaysFriction;
    447.             wheelcollider.GetComponent<WheelCollider>().forwardFriction = forwardFriction;
    448.  
    449.         }
    450.        
    451.         WheelCollider[] allWheelColliders = new WheelCollider[allWheelTransforms.Count];
    452.         allWheelColliders = GetComponentsInChildren<WheelCollider>();
    453.        
    454.         FrontLeftWheelCollider = allWheelColliders[0];
    455.         FrontRightWheelCollider = allWheelColliders[1];
    456.         RearLeftWheelCollider = allWheelColliders[2];
    457.         RearRightWheelCollider = allWheelColliders[3];
    458.        
    459.     }
    460.    
    461.     public void SoundsInitialize (){
    462.  
    463.         engineSoundOn = RCCCreateAudioSource.NewAudioSource(gameObject, "Engine Sound On AudioSource", 5, 100, 0, engineClipOn, true, true, false);
    464.         engineSoundOff = RCCCreateAudioSource.NewAudioSource(gameObject, "Engine Sound Off AudioSource", 5, 100, 0, engineClipOff, true, true, false);
    465.         windSound = RCCCreateAudioSource.NewAudioSource(gameObject, "Wind Sound AudioSource", 5, 10, 0, windClip, true, true, false);
    466.         brakeSound = RCCCreateAudioSource.NewAudioSource(gameObject, "Brake Sound AudioSource", 5, 10, 0, brakeClip, true, true, false);
    467.         skidSound = RCCCreateAudioSource.NewAudioSource(gameObject, "Skid Sound AudioSource", 5, 50, 0, asphaltSkidClip, true, false, false);
    468.        
    469.     }
    470.    
    471.     public void KillOrStartEngine (){
    472.        
    473.         if(engineRunning && !engineStarting){
    474.             engineRunning = false;
    475.         }else if(!engineStarting){
    476.             StartCoroutine("StartEngine");
    477.         }
    478.        
    479.     }
    480.    
    481.     public IEnumerator StartEngine (){
    482.  
    483.         engineRunning = false;
    484.         engineStarting = true;
    485.         if(!engineRunning)
    486.             engineStartSound = RCCCreateAudioSource.NewAudioSource(gameObject, "Engine Start AudioSource", 5, 10, 1, engineStartClip, false, true, true);
    487.         yield return new WaitForSeconds(1f);
    488.         engineRunning = true;
    489.         yield return new WaitForSeconds(1f);
    490.         engineStarting = false;
    491.  
    492.     }
    493.    
    494.     public void SmokeInit (){
    495.  
    496.         if(wheelSlipAsphalt){
    497.        
    498.             for(int i = 0; i < allWheelColliders.Length; i++){
    499.                 GameObject ps = (GameObject)Instantiate(wheelSlipAsphalt, transform.position, transform.rotation) as GameObject;
    500.                 _wheelSlipAsphalt.Add(ps.GetComponent<ParticleSystem>());
    501.                 ps.GetComponent<ParticleSystem>().enableEmission = false;
    502.                 ps.transform.SetParent(allWheelColliders[i].transform);
    503.                 ps.transform.localPosition = Vector3.zero;
    504.             }
    505.  
    506.         }
    507.  
    508.         if(wheelSlipSand){
    509.  
    510.             for(int i = 0; i < allWheelColliders.Length; i++){
    511.                 GameObject ps = (GameObject)Instantiate(wheelSlipSand, transform.position, transform.rotation) as GameObject;
    512.                 _wheelSlipSand.Add(ps.GetComponent<ParticleSystem>());
    513.                 ps.GetComponent<ParticleSystem>().enableEmission = false;
    514.                 ps.transform.SetParent(allWheelColliders[i].transform);
    515.                 ps.transform.localPosition = Vector3.zero;
    516.             }
    517.  
    518.         }
    519.  
    520.     }
    521.  
    522.     public void DamageInit (){
    523.  
    524.         if (deformableMeshFilters.Length == 0){
    525.  
    526.             MeshFilter[] allMeshFilters = GetComponentsInChildren<MeshFilter>();
    527.             List <MeshFilter> properMeshFilters = new List<MeshFilter>();
    528.  
    529.             foreach(MeshFilter mf in allMeshFilters){
    530.                 if(mf.gameObject != FrontLeftWheelTransform.gameObject && mf.gameObject != FrontRightWheelTransform.gameObject && mf.gameObject != RearLeftWheelTransform.gameObject && mf.gameObject != RearRightWheelTransform.gameObject)
    531.                     properMeshFilters.Add(mf);
    532.             }
    533.  
    534.             deformableMeshFilters = properMeshFilters.ToArray();
    535.  
    536.         }
    537.        
    538.         LoadOriginalMeshData();
    539.        
    540.         if(contactSparkle){
    541.            
    542.             for(int i = 0; i < maximumContactSparkle; i++){
    543.                 GameObject sparks = (GameObject)Instantiate(contactSparkle, transform.position, Quaternion.identity) as GameObject;
    544.                 sparks.transform.SetParent(allContactParticles.transform);
    545.                 contactSparkeList.Add(sparks.GetComponent<ParticleSystem>());
    546.                 sparks.GetComponent<ParticleSystem>().enableEmission = false;
    547.             }
    548.            
    549.         }
    550.  
    551.     }
    552.  
    553.     void SteeringWheelInit(){
    554.  
    555.         steeringWheelGameObject = steeringWheelTexture.gameObject;
    556.         steeringWheelRect = steeringWheelTexture.rectTransform;
    557.         steeringWheelCanvasGroup = steeringWheelTexture.GetComponent<CanvasGroup> ();
    558.         steeringWheelCenter = steeringWheelRect.position;
    559.         steeringWheelCanvasGroup.alpha = steeringWheelDefaultAlpha;
    560.        
    561.         SteeringWheelEventsInit ();
    562.  
    563.     }
    564.  
    565.     void LoadOriginalMeshData(){
    566.  
    567.         if (DeformationEnabled)
    568.         {
    569.             originalMeshData = new originalMeshVerts[deformableMeshFilters.Length];
    570.  
    571.             for (int i = 0; i < deformableMeshFilters.Length; i++)
    572.             {
    573.                 originalMeshData[i].meshVerts = deformableMeshFilters[i].mesh.vertices;
    574.             }
    575.         }
    576.  
    577.     }
    578.  
    579.     void Damage(){
    580.  
    581.         if (!sleep && repairNow){
    582.            
    583.             int k;
    584.             sleep = true;
    585.  
    586.             for(k = 0; k < deformableMeshFilters.Length; k++){
    587.  
    588.                 Vector3[] vertices = deformableMeshFilters[k].mesh.vertices;
    589.  
    590.                 if(originalMeshData==null)
    591.                     LoadOriginalMeshData();
    592.  
    593.                 for (int i = 0; i < vertices.Length; i++){
    594.  
    595.                     vertices[i] += (originalMeshData[k].meshVerts[i] - vertices[i]) * (Time.deltaTime * 2f);
    596.                     if((originalMeshData[k].meshVerts[i] - vertices[i]).magnitude >= minimumVertDistanceForDamagedMesh)
    597.                         sleep = false;
    598.  
    599.                 }
    600.  
    601.                 deformableMeshFilters[k].mesh.vertices=vertices;
    602.                 deformableMeshFilters[k].mesh.RecalculateNormals();
    603.                 deformableMeshFilters[k].mesh.RecalculateBounds();
    604.  
    605.             }
    606.            
    607.             if(sleep)
    608.                 repairNow = false;
    609.            
    610.         }
    611.  
    612.     }
    613.  
    614.     bool DeformationEnabled = false;
    615.  
    616.     void DeformMesh(Mesh mesh, Vector3[] originalMesh, Collision collision, float cos, Transform meshTransform, Quaternion rot){
    617.  
    618.         if (!DeformationEnabled) return;
    619.        
    620.         Vector3[] vertices = mesh.vertices;
    621.        
    622.         foreach (ContactPoint contact in collision.contacts){
    623.            
    624.             Vector3 point = meshTransform.InverseTransformPoint(contact.point);
    625.            
    626.             for (int i = 0; i < vertices.Length; i++){
    627.  
    628.                 if ((point - vertices[i]).magnitude < damageRadius){
    629.                     vertices[i] += rot * ((localVector * (damageRadius - (point - vertices[i]).magnitude) / damageRadius) * cos + (UnityEngine.Random.onUnitSphere * (randomizeVertices / 500f)));
    630.                     if (maximumDamage > 0 && ((vertices[i] - originalMesh[i]).magnitude) > maximumDamage){
    631.                         vertices[i] = originalMesh[i] + (vertices[i] - originalMesh[i]).normalized * (maximumDamage);
    632.                     }
    633.                 }
    634.             }
    635.            
    636.         }
    637.        
    638.         mesh.vertices = vertices;
    639.         mesh.RecalculateNormals();
    640.         mesh.RecalculateBounds();
    641.        
    642.     }
    643.  
    644.     void CollisionParticles(Vector3 contactPoint){
    645.        
    646.         for(int i = 0; i < contactSparkeList.Count; i++){
    647.             if(contactSparkeList[i].isPlaying)
    648.                 return;
    649.             contactSparkeList[i].transform.position = contactPoint;
    650.             contactSparkeList[i].enableEmission = true;
    651.             contactSparkeList[i].Play();
    652.         }
    653.        
    654.     }
    655.    
    656.     public void MobileGUI (){
    657.  
    658.         if(mobileController){
    659.             if(_mobileControllerType == MobileGUIType.NGUIController){
    660.                 defbrakePedalPosition = brakePedalNGUI.transform.position;
    661.             }else{
    662.                 defbrakePedalPosition = brakePedalUI.transform.position;
    663.             }
    664.         }
    665.        
    666.     }
    667.    
    668.     void Update (){
    669.  
    670.         if (this.GetComponent<VehicleBehaviour>().photonView.isMine)
    671.         {
    672.             canControl = this.GetComponent<VehicleBehaviour>().IsBeingDriven;
    673.         }
    674.         else
    675.             canControl = false;
    676.  
    677.         //Enables inputs for controlling vehicle.
    678.         if(canControl){
    679.             Lights();
    680.             ResetCar();
    681.             if(!AIController && !mobileController)
    682.                 KeyboardControlling();
    683.             if(steeringWheelControl && !steeringWheelRect && steeringWheelTexture)
    684.                 SteeringWheelInit();
    685.         }else if(!AIController){
    686.             gasInput = 0f;
    687.             brakeInput = 0f;
    688.             boostInput = 1f;
    689.             handbrakeInput = 1f;
    690.         }
    691.  
    692.         GearBox();
    693.  
    694.         if(!sleepingRigid){
    695.  
    696.             WheelAlign(FrontLeftWheelCollider, FrontLeftWheelTransform, _rotationValueFL);
    697.             WheelAlign(FrontRightWheelCollider, FrontRightWheelTransform, _rotationValueFR);
    698.             WheelAlign(RearLeftWheelCollider, RearLeftWheelTransform, _rotationValueRL);
    699.             WheelAlign(RearRightWheelCollider, RearRightWheelTransform, _rotationValueRR);
    700.  
    701.             _rotationValueFL = WheelRotation(FrontLeftWheelCollider, _rotationValueFL);
    702.             _rotationValueFR = WheelRotation(FrontRightWheelCollider, _rotationValueFR);
    703.             _rotationValueRL = WheelRotation(RearLeftWheelCollider, _rotationValueRL);
    704.             _rotationValueRR = WheelRotation(RearRightWheelCollider, _rotationValueRR);
    705.  
    706.             if(ExtraRearWheelsCollider.Length > 0){
    707.                 for(int i = 0; i < ExtraRearWheelsCollider.Length; i ++){
    708.                     WheelAlign(ExtraRearWheelsCollider[i], ExtraRearWheelsTransform[i], _rotationValueExtra[i]);
    709.                     _rotationValueExtra[i] = WheelRotation(ExtraRearWheelsCollider[i], _rotationValueExtra[i]);
    710.                 }
    711.             }
    712.  
    713.             for(int i = 0; i < allWheelColliders.Length; i++){
    714.                 WheelCamber(allWheelColliders[i]);
    715.             }
    716.  
    717.         }
    718.  
    719.         GroundPhysicsMaterial();
    720.         Sounds();
    721.  
    722.         if(useDamage)
    723.             Damage();
    724.  
    725.         if(chassis)
    726.             Chassis();
    727.  
    728.         if(dashBoard && canControl)
    729.             Dashboard();
    730.        
    731.     }
    732.    
    733.     void FixedUpdate (){
    734.  
    735.         if(canControl){
    736.             if(mobileController && !AIController){
    737.                 if(_mobileControllerType == MobileGUIType.NGUIController)
    738.                     NGUIControlling();
    739.                 if(_mobileControllerType == MobileGUIType.UIController)
    740.                     UIControlling();
    741.                 MobileSteeringInputs();
    742.             }
    743.             SteeringWheelControlling();
    744.         }
    745.  
    746.         Engine();
    747.         Braking();
    748.         AntiRollBars();
    749.         DownForce();
    750.         DriftVariables();
    751.         SmokeWeedEveryday(_groundMaterial);
    752.         ApplySteering(FrontLeftWheelCollider);
    753.         ApplySteering(FrontRightWheelCollider);
    754.  
    755.         if(steeringHelper)
    756.             SteerHelper();
    757.  
    758.         if(ESP){
    759.             if(transform.TransformDirection(rigid.angularVelocity).y > 0){
    760.                 ESPCheck(FrontLeftWheelCollider, FrontRightWheelCollider, RearLeftWheelCollider);
    761.                 ESPCheck(RearLeftWheelCollider, RearRightWheelCollider, FrontLeftWheelCollider);
    762.             }
    763.             if(transform.TransformDirection(rigid.angularVelocity).y < 0){
    764.                 ESPCheck(FrontLeftWheelCollider, FrontRightWheelCollider, RearRightWheelCollider);
    765.                 ESPCheck(RearLeftWheelCollider, RearRightWheelCollider, FrontRightWheelCollider);
    766.             }
    767.         }
    768.        
    769.     }
    770.    
    771.     public void Engine (){
    772.        
    773.         //Speed.
    774.         speed = rigid.velocity.magnitude * 3.6f;
    775.  
    776.         //Acceleration Calculation.
    777.         acceleration = 0f;
    778.         acceleration = (transform.InverseTransformDirection(rigid.velocity).z - lastVelocity) / Time.fixedDeltaTime;
    779.         lastVelocity = transform.InverseTransformDirection(rigid.velocity).z;
    780.        
    781.         //Drag Limit Depends On Vehicle Acceleration.
    782.         rigid.drag = Mathf.Clamp((acceleration / 50f), .05f, .1f);
    783.  
    784.         //Angular Drag Limit Depends On Vehicle Speed.
    785.         rigid.angularDrag = Mathf.Clamp((speed / maxspeed), .05f, .25f);
    786.  
    787.         //Steer Limit.
    788.         steerAngle = Mathf.Lerp(defSteerAngle, highspeedsteerAngle, (speed / highspeedsteerAngleAtspeed));
    789.  
    790.         //Driver SteeringWheel Transform.
    791.         if(SteeringWheel)
    792.             SteeringWheel.transform.rotation = transform.rotation * Quaternion.Euler(20, 0, (FrontLeftWheelCollider.steerAngle) * -6);
    793.  
    794.         if(rigid.velocity.magnitude < .01f && Mathf.Abs(steerInput) < .01f && Mathf.Abs(gasInput) < .01f && Mathf.Abs(rigid.angularVelocity.x) < .01f )
    795.             sleepingRigid = true;
    796.         else
    797.             sleepingRigid = false;
    798.  
    799.         WheelHit hit;
    800.         float rpm = 0f;
    801.  
    802.         if(_wheelTypeChoise == WheelType.RWD || _wheelTypeChoise == WheelType.AWD || _wheelTypeChoise == WheelType.DRIFT){
    803.             RearLeftWheelCollider.GetGroundHit(out hit);
    804.             wheelRPMToSpeed = ((Mathf.Abs((RearLeftWheelCollider.rpm * RearLeftWheelCollider.radius) + (RearRightWheelCollider.rpm * RearRightWheelCollider.radius)) / 2f) / 2.625f);
    805.         }
    806.  
    807.         if(_wheelTypeChoise == WheelType.FWD){
    808.             FrontLeftWheelCollider.GetGroundHit(out hit);
    809.             wheelRPMToSpeed = ((Mathf.Abs((FrontLeftWheelCollider.rpm * FrontLeftWheelCollider.radius) + (FrontRightWheelCollider.rpm * FrontRightWheelCollider.radius)) / 2f) / 2.625f);
    810.         }
    811.  
    812.         if(!reverseGear){
    813.             rpm = Mathf.Clamp(
    814.                 Mathf.Lerp(
    815.                 minEngineRPM, maxEngineRPM, (wheelRPMToSpeed - (currentGear != 0 ? gearSpeed[currentGear - 1] : 0)) / (gearSpeed[currentGear] * 1f))
    816.                 * (1 - clutchInput) + ((clutchInput * gasInput) * maxEngineRPM), minEngineRPM, maxEngineRPM);
    817.         }else{
    818.             if(automaticGear){
    819.                 rpm = Mathf.Clamp(
    820.                     Mathf.Lerp(
    821.                     minEngineRPM, maxEngineRPM, (wheelRPMToSpeed) / (gearSpeed[currentGear] * 2f))
    822.                     * (1 - clutchInput) + ((clutchInput * brakeInput) * maxEngineRPM), minEngineRPM, maxEngineRPM);
    823.             }else{
    824.                 rpm = Mathf.Clamp(
    825.                     Mathf.Lerp(
    826.                     minEngineRPM, maxEngineRPM, (wheelRPMToSpeed) / (gearSpeed[currentGear] * 2f))
    827.                     * (1 - clutchInput) + ((clutchInput * gasInput) * maxEngineRPM), minEngineRPM, maxEngineRPM);
    828.             }
    829.         }
    830.  
    831.         engineRPM = Mathf.Lerp(engineRPM, (rpm + UnityEngine.Random.Range(-50f, 50f)) * fuelInput, Time.deltaTime * 2f);
    832.  
    833.         if(engineRPM < (minEngineRPM / 2f) && !engineStarting){
    834.             if(canEngineStall)
    835.                 engineRunning = false;
    836.         }
    837.  
    838.         if(!engineRunning)
    839.             fuelInput = 0;
    840.         else
    841.             fuelInput = 1;
    842.        
    843.         //Auto Reverse Bool.
    844.         if(autoReverse){
    845.             canGoReverseNow = true;
    846.         }else{
    847.             if(brakeInput < .1f && speed < 5)
    848.                 canGoReverseNow = true;
    849.             else if(brakeInput > 0 && transform.InverseTransformDirection(rigid.velocity).z > 1f)
    850.                 canGoReverseNow = false;
    851.         }
    852.  
    853.         for(int i = 0; i < allWheelColliders.Length; i++){
    854.             allWheelColliders[i].wheelDampingRate = Mathf.Lerp(2f, 0f, gasInput);
    855.         }
    856.        
    857.         #region Wheel Type Motor Torque.
    858.  
    859.         //Applying WheelCollider Motor Torques Depends On Wheel Type Choice.
    860.         switch(_wheelTypeChoise){
    861.            
    862.         case WheelType.FWD:
    863.             ApplyMotorTorque(FrontLeftWheelCollider, engineTorque);
    864.             ApplyMotorTorque(FrontRightWheelCollider, engineTorque);
    865.             break;
    866.         case WheelType.RWD:
    867.             ApplyMotorTorque(RearLeftWheelCollider, engineTorque);
    868.             ApplyMotorTorque(RearRightWheelCollider, engineTorque);
    869.             break;
    870.         case WheelType.AWD:
    871.             ApplyMotorTorque(FrontLeftWheelCollider, engineTorque / 2f);
    872.             ApplyMotorTorque(FrontRightWheelCollider, engineTorque / 2f);
    873.             ApplyMotorTorque(RearLeftWheelCollider, engineTorque / 2f);
    874.             ApplyMotorTorque(RearRightWheelCollider, engineTorque / 2f);
    875.             break;
    876.         case WheelType.DRIFT:
    877.             ApplyMotorTorque(FrontLeftWheelCollider, (engineTorque * 30) / 100f);
    878.             ApplyMotorTorque(FrontRightWheelCollider, (engineTorque * 30) / 100f);
    879.             ApplyMotorTorque(RearLeftWheelCollider, (engineTorque * 70) / 100f);
    880.             ApplyMotorTorque(RearRightWheelCollider, (engineTorque * 70) / 100f);
    881.             break;
    882.  
    883.         }
    884.  
    885.         if(ExtraRearWheelsCollider.Length > 0 && applyEngineTorqueToExtraRearWheelColliders){
    886.  
    887.             for(int i = 0; i < ExtraRearWheelsCollider.Length; i++){
    888.                 ApplyMotorTorque(ExtraRearWheelsCollider[i], engineTorque);
    889.             }
    890.  
    891.         }
    892.        
    893.         #endregion Wheel Type
    894.        
    895.     }
    896.  
    897.     public void Sounds(){
    898.  
    899.         windSound.volume = Mathf.Lerp (0f, maxWindSoundVolume, speed / maxspeed);
    900.         windSound.pitch = UnityEngine.Random.Range(.9f, 1.1f);
    901.        
    902.         if(!reverseGear)
    903.             brakeSound.volume = Mathf.Lerp (0f, maxBrakeSoundVolume, Mathf.Clamp01((FrontLeftWheelCollider.brakeTorque + FrontRightWheelCollider.brakeTorque) / (brake * 2f)) * Mathf.Lerp(0f, 1f, FrontLeftWheelCollider.rpm / 50f));
    904.         else
    905.             brakeSound.volume = 0f;
    906.  
    907.     }
    908.  
    909.     public void ApplyMotorTorque(WheelCollider wc, float torque){
    910.  
    911.         if(TCS){
    912.  
    913.             WheelHit hit;
    914.             wc.GetGroundHit(out hit);
    915.  
    916.             if(Mathf.Abs(wc.rpm) >= 100){
    917.                 if(hit.forwardSlip > .25f){
    918.                     TCSAct = true;
    919.                     torque -= Mathf.Clamp(torque * (hit.forwardSlip) * TCSStrength, 0f, engineTorque);
    920.                 }else{
    921.                     TCSAct = false;
    922.                     torque += Mathf.Clamp(torque * (hit.forwardSlip) * TCSStrength, -engineTorque, 0f);
    923.                 }
    924.             }else{
    925.                 TCSAct = false;
    926.             }
    927.            
    928.         }
    929.  
    930.         if(OverTorque())
    931.             torque = 0;
    932.  
    933.         if(automaticGear){
    934.  
    935.             if(!reverseGear)
    936.                 wc.motorTorque = (torque * (1 - clutchInput)) * (Mathf.Clamp((gasInput * fuelInput), 0f, 1f) * boostInput) * engineTorqueCurve[currentGear].Evaluate(wheelRPMToSpeed);
    937.             else
    938.                 wc.motorTorque = (-torque * (1 - clutchInput)) * (Mathf.Clamp((brakeInput * fuelInput), 0f, 1f) * boostInput) * engineTorqueCurve[currentGear].Evaluate(wheelRPMToSpeed);
    939.  
    940.         }else{
    941.  
    942.             if(!reverseGear)
    943.                 wc.motorTorque = (torque * (1 - clutchInput)) * (Mathf.Clamp((gasInput * fuelInput), 0f, 1f) * boostInput) * engineTorqueCurve[currentGear].Evaluate(wheelRPMToSpeed);
    944.             else
    945.                 wc.motorTorque = (-torque * (1 - clutchInput)) * (Mathf.Clamp((gasInput * fuelInput), 0f, 1f) * boostInput) * engineTorqueCurve[currentGear].Evaluate(wheelRPMToSpeed);
    946.  
    947.         }
    948.  
    949.         ApplyEngineSound(wc.motorTorque);
    950.        
    951.     }
    952.  
    953.     public void ESPCheck(WheelCollider slippingLeftWheel, WheelCollider slippingRightWheel, WheelCollider correspondingWheel){
    954.  
    955.         WheelHit leftHit;
    956.         slippingLeftWheel.GetGroundHit(out leftHit);
    957.  
    958.         WheelHit rightHit;
    959.         slippingRightWheel.GetGroundHit(out rightHit);
    960.  
    961.         float totalSlip = Mathf.Abs(leftHit.sidewaysSlip) + Mathf.Abs(rightHit.sidewaysSlip);
    962.  
    963.         if(totalSlip > ESPThreshold){
    964.             ESPAct = true;
    965.             ApplyBrakeTorque(correspondingWheel, (brake * ESPStrength) * totalSlip);
    966.  
    967.         }else{
    968.             ESPAct = false;
    969.         }
    970.  
    971.     }
    972.  
    973.     public void ApplyBrakeTorque(WheelCollider wc, float brake){
    974.  
    975.         if(ABS && handbrakeInput <= .1f){
    976.  
    977.             WheelHit hit;
    978.             wc.GetGroundHit(out hit);
    979.  
    980.             if((Mathf.Abs(hit.forwardSlip) * brakeInput) >= ABSThreshold){
    981.                 ABSAct = true;
    982.                 brake = 0;
    983.             }else{
    984.                 ABSAct = false;
    985.             }
    986.  
    987.         }
    988.  
    989.         wc.brakeTorque = brake;
    990.  
    991.     }
    992.  
    993.     public void ApplySteering(WheelCollider wc){
    994.  
    995.         if(!applyCounterSteering)
    996.             wc.steerAngle = Mathf.Clamp((steerAngle * steerInput), -steerAngle, steerAngle);
    997.         else
    998.             wc.steerAngle = Mathf.Clamp((steerAngle * (steerInput + driftAngle)), -steerAngle, steerAngle);
    999.  
    1000.     }
    1001.  
    1002.     public void ApplyEngineSound(float input){
    1003.        
    1004.         //Engine Audio Volume.
    1005.         if(engineSoundOn){
    1006.  
    1007.             if(automaticGear){
    1008.  
    1009.                 if(!reverseGear)
    1010.                     engineSoundOn.volume = Mathf.Lerp (engineSoundOn.volume, Mathf.Clamp (gasInput, minEngineSoundVolume * fuelInput, maxEngineSoundVolume), Time.deltaTime * 50f);
    1011.                 else
    1012.                     engineSoundOn.volume = Mathf.Lerp (engineSoundOn.volume, Mathf.Clamp (brakeInput, minEngineSoundVolume * fuelInput, maxEngineSoundVolume), Time.deltaTime * 50f);
    1013.  
    1014.             }else{
    1015.  
    1016.                 engineSoundOn.volume = Mathf.Lerp (engineSoundOn.volume, Mathf.Clamp (gasInput, minEngineSoundVolume * fuelInput, maxEngineSoundVolume), Time.deltaTime * 50f);
    1017.  
    1018.             }
    1019.  
    1020.             if(engineRunning)
    1021.                 engineSoundOn.pitch = Mathf.Lerp ( engineSoundOn.pitch, Mathf.Lerp (minEngineSoundPitch * fuelInput, maxEngineSoundPitch, (engineRPM) / (maxEngineRPM)), Time.deltaTime * 50f);
    1022.             else
    1023.                 engineSoundOn.pitch = Mathf.Lerp ( engineSoundOn.pitch, 0, Time.deltaTime * 50f);
    1024.            
    1025.         }
    1026.        
    1027.         if(engineSoundOff){
    1028.  
    1029.             if(automaticGear){
    1030.  
    1031.                 if(!reverseGear)
    1032.                     engineSoundOff.volume = Mathf.Lerp (engineSoundOff.volume, Mathf.Clamp (((1 + (-gasInput)) * fuelInput), minEngineSoundVolume * fuelInput, .5f), Time.deltaTime * 50f);
    1033.                 else
    1034.                     engineSoundOff.volume = Mathf.Lerp (engineSoundOff.volume, Mathf.Clamp (((1 + (-brakeInput)) * fuelInput), minEngineSoundVolume * fuelInput, .5f), Time.deltaTime * 50f);
    1035.  
    1036.             }else{
    1037.  
    1038.                 engineSoundOff.volume = Mathf.Lerp (engineSoundOff.volume, Mathf.Clamp (((1 + (gasInput)) * fuelInput), minEngineSoundVolume * fuelInput, .5f), Time.deltaTime * 50f);
    1039.  
    1040.             }
    1041.  
    1042.             if(engineRunning)
    1043.                 engineSoundOff.pitch = Mathf.Lerp ( engineSoundOff.pitch, Mathf.Lerp (minEngineSoundPitch * fuelInput, maxEngineSoundPitch, (engineRPM) / (maxEngineRPM)), Time.deltaTime * 50f);
    1044.             else
    1045.                 engineSoundOff.pitch = Mathf.Lerp ( engineSoundOff.pitch, 0, Time.deltaTime * 50f);
    1046.  
    1047.         }
    1048.  
    1049.     }
    1050.    
    1051.     public void Braking (){
    1052.  
    1053.         //Handbrake
    1054.         if(handbrakeInput > .1f){
    1055.            
    1056.             ApplyBrakeTorque(RearLeftWheelCollider, (brake * 1.5f) * handbrakeInput);
    1057.             ApplyBrakeTorque(RearRightWheelCollider, (brake * 1.5f) * handbrakeInput);
    1058.            
    1059.         }else{
    1060.            
    1061.             // Braking.
    1062.  
    1063.             if(automaticGear){
    1064.  
    1065.                 if(brakeInput > .1f && !reverseGear){
    1066.                     ApplyBrakeTorque(FrontLeftWheelCollider, brake * (brakeInput));
    1067.                     ApplyBrakeTorque(FrontRightWheelCollider, brake * (brakeInput));
    1068.                     ApplyBrakeTorque(RearLeftWheelCollider, brake * brakeInput / 2f);
    1069.                     ApplyBrakeTorque(RearRightWheelCollider, brake * brakeInput / 2f);
    1070.                 }else if(brakeInput > .1f && reverseGear){
    1071.                     ApplyBrakeTorque(FrontLeftWheelCollider, 0f);
    1072.                     ApplyBrakeTorque(FrontRightWheelCollider, 0f);
    1073.                     ApplyBrakeTorque(RearLeftWheelCollider, 0f);
    1074.                     ApplyBrakeTorque(RearRightWheelCollider, 0f);
    1075.                 }else if(brakeInput < .1f){
    1076.                     ApplyBrakeTorque(FrontLeftWheelCollider, 0f);
    1077.                     ApplyBrakeTorque(FrontRightWheelCollider, 0f);
    1078.                     ApplyBrakeTorque(RearLeftWheelCollider, 0f);
    1079.                     ApplyBrakeTorque(RearRightWheelCollider, 0f);
    1080.                 }
    1081.  
    1082.             }else{
    1083.  
    1084.                 if(brakeInput > .1f && !reverseGear){
    1085.                     ApplyBrakeTorque(FrontLeftWheelCollider, brake * (brakeInput));
    1086.                     ApplyBrakeTorque(FrontRightWheelCollider, brake * (brakeInput));
    1087.                     ApplyBrakeTorque(RearLeftWheelCollider, brake * brakeInput / 2f);
    1088.                     ApplyBrakeTorque(RearRightWheelCollider, brake * brakeInput / 2f);
    1089.                 }else if(brakeInput > .1f && reverseGear){
    1090.                     ApplyBrakeTorque(FrontLeftWheelCollider, brake * (brakeInput));
    1091.                     ApplyBrakeTorque(FrontRightWheelCollider, brake * (brakeInput));
    1092.                     ApplyBrakeTorque(RearLeftWheelCollider, brake * brakeInput);
    1093.                     ApplyBrakeTorque(RearRightWheelCollider, brake * brakeInput);
    1094.                 }else if(brakeInput < .1f){
    1095.                     ApplyBrakeTorque(FrontLeftWheelCollider, 0f);
    1096.                     ApplyBrakeTorque(FrontRightWheelCollider, 0f);
    1097.                     ApplyBrakeTorque(RearLeftWheelCollider, 0f);
    1098.                     ApplyBrakeTorque(RearRightWheelCollider, 0f);
    1099.                 }
    1100.  
    1101.             }
    1102.            
    1103.         }
    1104.        
    1105.     }
    1106.    
    1107.     public void AntiRollBars (){
    1108.  
    1109.         WheelHit FrontWheelHit;
    1110.        
    1111.         float travelFL = 1.0f;
    1112.         float travelFR = 1.0f;
    1113.        
    1114.         bool groundedFL= FrontLeftWheelCollider.GetGroundHit(out FrontWheelHit);
    1115.        
    1116.         if (groundedFL)
    1117.             travelFL = (-FrontLeftWheelCollider.transform.InverseTransformPoint(FrontWheelHit.point).y - FrontLeftWheelCollider.radius) / FrontLeftWheelCollider.suspensionDistance;
    1118.        
    1119.         bool groundedFR= FrontRightWheelCollider.GetGroundHit(out FrontWheelHit);
    1120.        
    1121.         if (groundedFR)
    1122.             travelFR = (-FrontRightWheelCollider.transform.InverseTransformPoint(FrontWheelHit.point).y - FrontRightWheelCollider.radius) / FrontRightWheelCollider.suspensionDistance;
    1123.        
    1124.         float antiRollForceFront= (travelFL - travelFR) * antiRoll;
    1125.        
    1126.         if (groundedFL)
    1127.             rigid.AddForceAtPosition(FrontLeftWheelCollider.transform.up * -antiRollForceFront, FrontLeftWheelCollider.transform.position);
    1128.         if (groundedFR)
    1129.             rigid.AddForceAtPosition(FrontRightWheelCollider.transform.up * antiRollForceFront, FrontRightWheelCollider.transform.position);
    1130.        
    1131.         WheelHit RearWheelHit;
    1132.        
    1133.         float travelRL = 1.0f;
    1134.         float travelRR = 1.0f;
    1135.        
    1136.         bool groundedRL= RearLeftWheelCollider.GetGroundHit(out RearWheelHit);
    1137.        
    1138.         if (groundedRL)
    1139.             travelRL = (-RearLeftWheelCollider.transform.InverseTransformPoint(RearWheelHit.point).y - RearLeftWheelCollider.radius) / RearLeftWheelCollider.suspensionDistance;
    1140.        
    1141.         bool groundedRR= RearRightWheelCollider.GetGroundHit(out RearWheelHit);
    1142.        
    1143.         if (groundedRR)
    1144.             travelRR = (-RearRightWheelCollider.transform.InverseTransformPoint(RearWheelHit.point).y - RearRightWheelCollider.radius) / RearRightWheelCollider.suspensionDistance;
    1145.        
    1146.         float antiRollForceRear= (travelRL - travelRR) * antiRoll;
    1147.        
    1148.         if (groundedRL)
    1149.             rigid.AddForceAtPosition(RearLeftWheelCollider.transform.up * -antiRollForceRear, RearLeftWheelCollider.transform.position);
    1150.         if (groundedRR)
    1151.             rigid.AddForceAtPosition(RearRightWheelCollider.transform.up * antiRollForceRear, RearRightWheelCollider.transform.position);
    1152.  
    1153.         if (groundedRR && groundedRL && AIController)
    1154.             rigid.AddRelativeTorque((Vector3.up * (steerInput * gasInput)) * 2000f);
    1155.  
    1156.         if(_wheelTypeChoise == WheelType.DRIFT && groundedRR && groundedRL)
    1157.             rigid.AddRelativeTorque((Vector3.up * (steerInput * gasInput)) * 5000f);
    1158.  
    1159.     }
    1160.  
    1161.     public void DownForce(){
    1162.         rigid.AddForce(-transform.up * (downForce * rigid.velocity.magnitude));
    1163.     }
    1164.  
    1165.     public void SteerHelper(){
    1166.  
    1167.         for (int i = 0; i < allWheelColliders.Length; i++){
    1168.             WheelHit hit;
    1169.             allWheelColliders[i].GetGroundHit(out hit);
    1170.             if (hit.normal == Vector3.zero)
    1171.                 return;
    1172.         }
    1173.  
    1174.         if (Mathf.Abs(oldRotation - transform.eulerAngles.y) < 10f){
    1175.             float turnadjust = (transform.eulerAngles.y - oldRotation) * steerHelper;
    1176.             Quaternion velRotation = Quaternion.AngleAxis(turnadjust, Vector3.up);
    1177.             rigid.velocity = velRotation * rigid.velocity;
    1178.         }
    1179.  
    1180.         oldRotation = transform.eulerAngles.y;
    1181.  
    1182.     }
    1183.    
    1184.     public void MobileSteeringInputs (){
    1185.        
    1186.         //Accelerometer Inputs.
    1187.         if(useAccelerometerForSteer){
    1188.            
    1189.             steerInput = Input.acceleration.x * gyroTiltMultiplier;
    1190.  
    1191.         //TouchScreen Inputs.
    1192.         }else if(steeringWheelControl){
    1193.  
    1194.             steerInput = GetSteeringWheelInput();
    1195.        
    1196.         }
    1197.        
    1198.     }
    1199.    
    1200.     public void SteeringWheelControlling (){
    1201.  
    1202.         if(!steeringWheelCanvasGroup || !steeringWheelRect || !steeringWheelControl){
    1203.             if(steeringWheelGameObject)
    1204.                 steeringWheelGameObject.SetActive(false);
    1205.             return;
    1206.         }
    1207.  
    1208.         if(!steeringWheelGameObject.activeSelf)
    1209.             steeringWheelGameObject.SetActive(true);
    1210.  
    1211.         if(steeringWheelPressed){
    1212.  
    1213.             if(steeringWheelInteractable){
    1214.  
    1215.                 steeringWheelCanvasGroup.alpha = steeringWheelActiveAlpha;
    1216.                 steeringWheelNewAngle = Vector2.Angle(Vector2.up, steeringWheelTouchPos - steeringWheelCenter);
    1217.  
    1218.                 if(Vector2.Distance( steeringWheelTouchPos, steeringWheelCenter ) > steeringWheelCenterDeadZoneRadius){
    1219.  
    1220.                     if(steeringWheelTouchPos.x > steeringWheelCenter.x)
    1221.                         steeringWheelAngle += steeringWheelNewAngle - steeringWheelTempAngle;
    1222.                     else
    1223.                         steeringWheelAngle -= steeringWheelNewAngle - steeringWheelTempAngle;
    1224.  
    1225.                 }
    1226.  
    1227.                 if(steeringWheelAngle > steeringWheelMaximumsteerAngle)
    1228.                     steeringWheelAngle = steeringWheelMaximumsteerAngle;
    1229.                 else if(steeringWheelAngle < -steeringWheelMaximumsteerAngle)
    1230.                     steeringWheelAngle = -steeringWheelMaximumsteerAngle;
    1231.                
    1232.                 steeringWheelTempAngle = steeringWheelNewAngle;
    1233.  
    1234.             }
    1235.  
    1236.         }else{
    1237.  
    1238.             steeringWheelCanvasGroup.alpha = steeringWheelDefaultAlpha;
    1239.  
    1240.             if(!Mathf.Approximately(0f, steeringWheelAngle)){
    1241.  
    1242.                 float deltaAngle = steeringWheelResetPosSpeed;
    1243.                
    1244.                 if(Mathf.Abs(deltaAngle) > Mathf.Abs(steeringWheelAngle)){
    1245.                     steeringWheelAngle = 0f;
    1246.                     return;
    1247.                 }
    1248.                
    1249.                 if(steeringWheelAngle > 0f)
    1250.                     steeringWheelAngle -= deltaAngle;
    1251.                 else
    1252.                     steeringWheelAngle += deltaAngle;
    1253.  
    1254.             }
    1255.  
    1256.         }
    1257.  
    1258.         steeringWheelRect.eulerAngles = new Vector3 (0, 0, -steeringWheelAngle);
    1259.        
    1260.     }
    1261.     #region PlayerInputs
    1262.     public void KeyboardControlling (){
    1263.  
    1264.         //Start Or Stop The Engine.
    1265.         if(Input.GetKeyDown(KeyCode.I))
    1266.             KillOrStartEngine();
    1267.  
    1268.         //Motor Input.
    1269.         if(!changingGear){
    1270.             gasInput = Mathf.Lerp(gasInput, Mathf.Clamp01(Input.GetAxis("Vertical")), Time.deltaTime * 10f);
    1271.         }else{
    1272.             gasInput = Mathf.Lerp(gasInput, 0, Time.deltaTime * 10f);
    1273.         }
    1274.  
    1275.         brakeInput = Mathf.Lerp(brakeInput, -Mathf.Clamp(Input.GetAxis("Vertical"), -1f, 0f), Time.deltaTime * 10f);
    1276.         handbrakeInput = Input.GetAxis("Jump");
    1277.  
    1278.         //Steering Input.
    1279.         if(Mathf.Abs(Input.GetAxis("Horizontal")) > .05f)
    1280.             steerInput = Mathf.Lerp (steerInput, Input.GetAxis("Horizontal"), Time.deltaTime * 20f);
    1281.         else
    1282.             steerInput = Mathf.Lerp (steerInput, Input.GetAxis("Horizontal"), Time.deltaTime * 20f);
    1283.        
    1284.         //Boost Input.
    1285.         if(Input.GetButton("Fire2"))
    1286.             boostInput = 2.5f;
    1287.         else
    1288.             boostInput = 1f;
    1289.  
    1290.     }
    1291.    
    1292.     public void NGUIControlling (){
    1293.        
    1294.         //Motor Input.
    1295.         if(!changingGear)
    1296.             gasInput = gasPedalNGUI.input;
    1297.         else
    1298.             gasInput = 0;
    1299.  
    1300.         //Brake Input.
    1301.         brakeInput = brakePedalNGUI.input;
    1302.        
    1303.         //Steer Input.
    1304.         if(!useAccelerometerForSteer && !steeringWheelControl)
    1305.             steerInput = rightArrowNGUI.input + (-leftArrowNGUI.input);
    1306.        
    1307.         //Handbrake Input.
    1308.         if(handbrakeNGUI.input > .1f)
    1309.             handbrakeInput = 1;
    1310.         else
    1311.             handbrakeInput = 0;
    1312.        
    1313.         //Boost Input.
    1314.         if(boostNGUI)
    1315.             boostInput = Mathf.Clamp(boostNGUI.input * 2f, 1f, 2.5f);
    1316.        
    1317.     }
    1318.  
    1319.     public void UIControlling (){
    1320.        
    1321.         //Motor Input.
    1322.         if(!changingGear)
    1323.             gasInput = gasPedalUI.input;
    1324.         else
    1325.             gasInput = 0;
    1326.  
    1327.         //Brake Input.
    1328.         brakeInput = brakePedalUI.input;
    1329.        
    1330.         //Steer Input.
    1331.         if(!useAccelerometerForSteer && !steeringWheelControl)
    1332.             steerInput = rightArrowUI.input + (-leftArrowUI.input);
    1333.        
    1334.         //Handbrake Input.
    1335.         if(handbrakeUI.input > .1f)
    1336.             handbrakeInput = 1;
    1337.         else if(handbrakeUI.input < .9f)
    1338.             handbrakeInput = 0;
    1339.  
    1340.         //Boost Input.
    1341.         if(boostUI)
    1342.             boostInput = Mathf.Clamp(boostUI.input * 2f, 1f, 2.5f);
    1343.        
    1344.     }
    1345.     #endregion
    1346.     public void GearBox (){
    1347.  
    1348.         if(speed <= gearSpeed[0]){
    1349.  
    1350.             if(handbrakeInput < .1f){
    1351.  
    1352.                 if(!reverseGear && automaticGear)
    1353.                     clutchInput = Mathf.Lerp(clutchInput, (Mathf.Lerp(1f, (Mathf.Lerp(.25f, 0f, wheelRPMToSpeed / gearSpeed[0])), gasInput)), Time.deltaTime * 50f);
    1354.                 else if(automaticGear)
    1355.                     clutchInput = Mathf.Lerp(clutchInput, (Mathf.Lerp(1f, (Mathf.Lerp(.25f, 0f, wheelRPMToSpeed / gearSpeed[0])), brakeInput)), Time.deltaTime * 50f);
    1356.                 else if(!automaticGear && !reverseGear)
    1357.                     clutchInput = Mathf.Lerp(clutchInput, (Mathf.Lerp(1f, (Mathf.Lerp(.25f, 0f, wheelRPMToSpeed / gearSpeed[0])), gasInput)), Time.deltaTime * 50f);
    1358.                 else
    1359.                     clutchInput = Mathf.Lerp(clutchInput, (Mathf.Lerp(1f, (Mathf.Lerp(.25f, 0f, wheelRPMToSpeed / gearSpeed[0])), gasInput)), Time.deltaTime * 50f);
    1360.  
    1361.             }else{
    1362.  
    1363.                 clutchInput = Mathf.Lerp(clutchInput, 1, Time.deltaTime * 10f);
    1364.  
    1365.             }
    1366.  
    1367.         }else{
    1368.             if(changingGear)
    1369.                 clutchInput = Mathf.Lerp(clutchInput, 1, Time.deltaTime * 10f);
    1370.             else
    1371.                 clutchInput = Mathf.Lerp(clutchInput, 0, Time.deltaTime * 10f);
    1372.         }
    1373.  
    1374.         if(clutchInput > 1)
    1375.             clutchInput = 1;
    1376.         if(clutchInput < 0)
    1377.             clutchInput = 0;
    1378.  
    1379.         //Reversing Bool.
    1380.         if(!AIController){
    1381.             if(brakeInput > .1f  && transform.InverseTransformDirection(rigid.velocity).z < 1f && canGoReverseNow && automaticGear && !changingGear && !reverseGear)
    1382.                 StartCoroutine("ChangingGear", -1);
    1383.             else if(gasInput > .1f && reverseGear && !changingGear && automaticGear)
    1384.                 StartCoroutine("ChangingGear", 0);
    1385.         }
    1386.  
    1387.         if(automaticGear){
    1388.  
    1389.             if(currentGear < totalGears - 1 && !changingGear && !driftingNow){
    1390.                 if(speed >= (gearSpeed[currentGear] * 1.1f) && FrontLeftWheelCollider.rpm > 0){
    1391.                     StartCoroutine("ChangingGear", currentGear + 1);
    1392.                 }
    1393.             }
    1394.            
    1395.             if(currentGear > 0){
    1396.  
    1397.                 if(!changingGear){
    1398.  
    1399.                     if(speed < (gearSpeed[currentGear - 1] * .9f)){
    1400.                         StartCoroutine("ChangingGear", currentGear - 1);
    1401.                     }
    1402.  
    1403.                 }
    1404.  
    1405.             }
    1406.            
    1407.         }else{
    1408.            
    1409.             if(currentGear < totalGears - 1 && !changingGear){
    1410.                 if(Input.GetButtonDown("RCCShiftUp")){
    1411.                     if(!reverseGear)
    1412.                         StartCoroutine("ChangingGear", currentGear + 1);
    1413.                     else
    1414.                         StartCoroutine("ChangingGear", 0);
    1415.                 }
    1416.             }
    1417.            
    1418.             if(currentGear >= 0){
    1419.                 if(Input.GetButtonDown("RCCShiftDown")){
    1420.                     StartCoroutine("ChangingGear", currentGear - 1);  
    1421.                 }
    1422.             }
    1423.            
    1424.         }
    1425.        
    1426.     }
    1427.    
    1428.     IEnumerator ChangingGear(int gear){
    1429.  
    1430.         changingGear = true;
    1431.  
    1432.         if(demoGUI)
    1433.             print ("Shifted to: " + (gear).ToString());
    1434.  
    1435.         if(gearShiftingClips.Length > 0)
    1436.             gearShiftingSound = RCCCreateAudioSource.NewAudioSource(gameObject, "Gear Shifting AudioSource", 5, 5, maxGearShiftingSoundVolume, gearShiftingClips[UnityEngine.Random.Range(0, gearShiftingClips.Length)], false, true, true);
    1437.        
    1438.         yield return new WaitForSeconds(gearShiftingDelay);
    1439.  
    1440.         if(gear == -1){
    1441.             currentGear = 0;
    1442.             reverseGear = true;
    1443.         }else{
    1444.             currentGear = gear;
    1445.             reverseGear = false;
    1446.         }
    1447.  
    1448.         changingGear = false;
    1449.  
    1450.     }
    1451.    
    1452.     public void WheelAlign (WheelCollider wc, Transform wm, float rotation){
    1453.  
    1454.         RaycastHit hit;
    1455.         WheelHit CorrespondingGroundHit;
    1456.  
    1457.         Vector3 ColliderCenterPoint = wc.transform.TransformPoint(wc.center);
    1458.         wc.GetGroundHit(out CorrespondingGroundHit);
    1459.        
    1460.         if(Physics.Raycast(ColliderCenterPoint, -wc.transform.up, out hit, (wc.suspensionDistance + wc.radius) * transform.localScale.y) && !hit.collider.isTrigger && hit.transform.root != transform){
    1461.             wm.transform.position = hit.point + (wc.transform.up * wc.radius) * transform.localScale.y;
    1462.             float extension = (-wc.transform.InverseTransformPoint(CorrespondingGroundHit.point).y - wc.radius) / wc.suspensionDistance;
    1463.             Debug.DrawLine(CorrespondingGroundHit.point, CorrespondingGroundHit.point + wc.transform.up * (CorrespondingGroundHit.force / rigid.mass), extension <= 0.0 ? Color.magenta : Color.white);
    1464.             Debug.DrawLine(CorrespondingGroundHit.point, CorrespondingGroundHit.point - wc.transform.forward * CorrespondingGroundHit.forwardSlip * 2f, Color.green);
    1465.             Debug.DrawLine(CorrespondingGroundHit.point, CorrespondingGroundHit.point - wc.transform.right * CorrespondingGroundHit.sidewaysSlip * 2f, Color.red);
    1466.         }else{
    1467.             wm.transform.position = ColliderCenterPoint - (wc.transform.up * wc.suspensionDistance) * transform.localScale.y;
    1468.         }
    1469.        
    1470.         rotation += wc.rpm * 6 * Time.deltaTime;
    1471.         wm.transform.rotation = wc.transform.rotation * Quaternion.Euler(rotation, wc.steerAngle, wc.transform.rotation.z);
    1472.        
    1473.     }
    1474.  
    1475.     private float WheelRotation(WheelCollider wc, float rotation){
    1476.  
    1477.         rotation += wc.rpm * 6 * Time.deltaTime;
    1478.         return rotation;
    1479.  
    1480.     }
    1481.  
    1482.     public void WheelCamber (WheelCollider wc){
    1483.        
    1484.         WheelHit CorrespondingGroundHit;
    1485.         Vector3 wheelLocalEuler;
    1486.  
    1487.         wc.GetGroundHit(out CorrespondingGroundHit);
    1488.         float handling = Mathf.Lerp (-2f, 2f, CorrespondingGroundHit.force / 7500f);
    1489.  
    1490.         if(wc.transform.localPosition.x < 0)
    1491.             wheelLocalEuler = new Vector3(wc.transform.localEulerAngles.x, wc.transform.localEulerAngles.y, (-handling));
    1492.         else
    1493.             wheelLocalEuler = new Vector3(wc.transform.localEulerAngles.x, wc.transform.localEulerAngles.y, (handling));
    1494.  
    1495.         Quaternion wheelCamber = Quaternion.Euler(wheelLocalEuler);
    1496.         wc.transform.localRotation = wheelCamber;
    1497.        
    1498.     }
    1499.    
    1500.     public void Dashboard (){
    1501.  
    1502.         if(_dashboardType == DashboardType.NGUIDashboard){
    1503.        
    1504.             if(!UIInputs){
    1505.                 Debug.LogError("If you gonna use NGUI Dashboard, your NGUI Root must have ''RCCNGUIDashboardInputs''. First be sure your NGUI Root has ''RCCNGUIDashboardInputs.cs''.");
    1506.                 dashBoard = false;
    1507.                 return;
    1508.             }
    1509.  
    1510.             UIInputs.RPM = engineRPM;
    1511.             UIInputs.KMH = speed;
    1512.             UIInputs.Gear = FrontLeftWheelCollider.rpm > -10 ? currentGear : -1f;
    1513.  
    1514.             UIInputs.ABS = ABSAct;
    1515.             UIInputs.ESP = ESPAct;
    1516.             UIInputs.Park = handbrakeInput > .1f ? true : false;
    1517.             UIInputs.Headlights = headLightsOn;
    1518.            
    1519.             RPMNeedleRotation = (engineRPM / 50f);
    1520.             KMHNeedleRotation = (speed / 360f) * 470f;
    1521.  
    1522.             smoothedNeedleRotation = Mathf.Lerp (smoothedNeedleRotation, RPMNeedleRotation, Time.deltaTime * 5);
    1523.            
    1524.             RPMNeedleNGUI.transform.eulerAngles = new Vector3(RPMNeedleNGUI.transform.eulerAngles.x ,RPMNeedleNGUI.transform.eulerAngles.y, -smoothedNeedleRotation);
    1525.             KMHNeedleNGUI.transform.eulerAngles = new Vector3(KMHNeedleNGUI.transform.eulerAngles.x ,KMHNeedleNGUI.transform.eulerAngles.y, -KMHNeedleRotation);
    1526.  
    1527.         }
    1528.  
    1529.         if(_dashboardType == DashboardType.UIDashboard){
    1530.            
    1531.             if(!UIInputs){
    1532.                 Debug.LogError("If you gonna use UI Dashboard, your Canvas Root must have ''RCCUIDashboardInputs''. First be sure your Canvas Root has ''RCCUIDashboardInputs.cs''.");
    1533.                 dashBoard = false;
    1534.                 return;
    1535.             }
    1536.  
    1537.             UIInputs.RPM = engineRPM;
    1538.             UIInputs.KMH = speed;
    1539.             UIInputs.Gear = FrontLeftWheelCollider.rpm > -10 ? currentGear : -1f;
    1540.  
    1541.             if(dashBoard && UIInputs)
    1542.                 UIInputs.NGear = changingGear;
    1543.            
    1544.             UIInputs.ABS = ABSAct;
    1545.             UIInputs.ESP = ESPAct;
    1546.             UIInputs.Park = handbrakeInput > .1f ? true : false;
    1547.             UIInputs.Headlights = headLightsOn;
    1548.            
    1549.             RPMNeedleRotation = (engineRPM / 50f);
    1550.             KMHNeedleRotation = (speed * 1.25f);
    1551.  
    1552.             smoothedNeedleRotation = Mathf.Lerp (smoothedNeedleRotation, RPMNeedleRotation, Time.deltaTime * 5f);
    1553.            
    1554.             RPMNeedle.transform.eulerAngles = new Vector3(RPMNeedle.transform.eulerAngles.x ,RPMNeedle.transform.eulerAngles.y, -smoothedNeedleRotation);
    1555.             KMHNeedle.transform.eulerAngles = new Vector3(KMHNeedle.transform.eulerAngles.x ,KMHNeedle.transform.eulerAngles.y, -KMHNeedleRotation);
    1556.            
    1557.         }
    1558.        
    1559.     }
    1560.    
    1561.     public void SmokeWeedEveryday (GroundMaterial ground){
    1562.  
    1563.         for(int i = 0; i < allWheelColliders.Length; i++){
    1564.  
    1565.             WheelHit CorrespondingGroundHit;
    1566.             allWheelColliders[i].GetGroundHit(out CorrespondingGroundHit);
    1567.  
    1568.             if(_wheelSlipAsphalt.Count > 0 && ground == GroundMaterial.Asphalt){
    1569.  
    1570.                 if(Mathf.Abs(CorrespondingGroundHit.sidewaysSlip) > .25f || Mathf.Abs(CorrespondingGroundHit.forwardSlip) > .35f){
    1571.                     if(!_wheelSlipAsphalt[i].enableEmission && speed > 1)
    1572.                         _wheelSlipAsphalt[i].enableEmission = true;
    1573.                 }else{
    1574.                     if(_wheelSlipAsphalt[i].enableEmission)
    1575.                         _wheelSlipAsphalt[i].enableEmission = false;
    1576.                 }
    1577.  
    1578.             }else if(_wheelSlipAsphalt.Count > 0){
    1579.                 if(_wheelSlipAsphalt[i].enableEmission)
    1580.                     _wheelSlipAsphalt[i].enableEmission = false;
    1581.             }
    1582.  
    1583.             if(_wheelSlipSand.Count > 0 && ground == GroundMaterial.Sand && CorrespondingGroundHit.point != Vector3.zero){
    1584.                
    1585.                 if(Mathf.Abs(CorrespondingGroundHit.sidewaysSlip) > .25f || Mathf.Abs(CorrespondingGroundHit.forwardSlip) > .35f || speed > 20){
    1586.                     if(!_wheelSlipSand[i].enableEmission && speed > 1)
    1587.                         _wheelSlipSand[i].enableEmission = true;
    1588.                 }else{
    1589.                     if(_wheelSlipSand[i].enableEmission)
    1590.                         _wheelSlipSand[i].enableEmission = false;
    1591.                 }
    1592.                
    1593.             }else if(_wheelSlipSand.Count > 0){
    1594.                 if(_wheelSlipSand[i].enableEmission)
    1595.                     _wheelSlipSand[i].enableEmission = false;
    1596.             }
    1597.  
    1598.         }
    1599.        
    1600.         if(exhaustGas.Length > 0 && engineRunning){
    1601.  
    1602.             for(int i = 0; i < exhaustGas.Length; i++){
    1603.                 if(speed < 30){
    1604.                     if(!exhaustGas[i].enableEmission)
    1605.                         exhaustGas[i].enableEmission = true;
    1606.                     if(gasInput > .05f){
    1607.                         exhaustGas[i].emissionRate = 25;
    1608.                         exhaustGas[i].startSpeed = 5;
    1609.                         exhaustGas[i].startSize = 5;
    1610.                     }else{
    1611.                         exhaustGas[i].emissionRate = 5;
    1612.                         exhaustGas[i].startSpeed = 1;
    1613.                         exhaustGas[i].startSize = 3;
    1614.                     }
    1615.                 }else{
    1616.                     if(exhaustGas[i].enableEmission)
    1617.                         exhaustGas[i].enableEmission = false;
    1618.                 }
    1619.             }
    1620.  
    1621.         }else if(exhaustGas.Length > 0){
    1622.  
    1623.             for(int i = 0; i < exhaustGas.Length; i++){
    1624.                 if(exhaustGas[i].enableEmission)
    1625.                     exhaustGas[i].enableEmission = false;
    1626.             }
    1627.  
    1628.         }
    1629.        
    1630.     }
    1631.  
    1632.     public void DriftVariables(){
    1633.        
    1634.         WheelHit hit;
    1635.         RearRightWheelCollider.GetGroundHit(out hit);
    1636.        
    1637.         if(speed > 50f)
    1638.             driftAngle = hit.sidewaysSlip / 1f;
    1639.         else
    1640.             driftAngle = 0f;
    1641.        
    1642.         if(Mathf.Abs(hit.sidewaysSlip) > .25f)
    1643.             driftingNow = true;
    1644.         else
    1645.             driftingNow = false;
    1646.  
    1647.         if(_wheelTypeChoise == WheelType.DRIFT){
    1648.             if(ESP){
    1649.                 Debug.Log("ESP Is Disabled For Accurate Drifting For " + transform.name);
    1650.                 ESP = false;
    1651.             }
    1652.             if(TCS){
    1653.                 Debug.Log("TCS Is Disabled For Accurate Drifting For " + transform.name);
    1654.                 TCS = false;
    1655.             }
    1656.             if(ABS){
    1657.                 Debug.Log("ABS Is Disabled For Accurate Drifting For " + transform.name);
    1658.                 ABS = false;
    1659.             }
    1660.             if(steeringHelper){
    1661.                 Debug.Log("Steering Helper Is Disabled For Accurate Drifting For " + transform.name);
    1662.                 steeringHelper = false;
    1663.             }
    1664.         }
    1665.        
    1666.     }
    1667.    
    1668.     public void GroundPhysicsMaterial (){
    1669.  
    1670.         if(sleepingRigid)
    1671.             return;
    1672.        
    1673.         WheelHit wheelhit;
    1674.         RearLeftWheelCollider.GetGroundHit(out wheelhit);
    1675.  
    1676.         if(RearLeftWheelCollider.GetGroundHit(out wheelhit)){
    1677.  
    1678.             if(asphaltPhysicsMaterial){
    1679.                 if(wheelhit.collider.material.name == asphaltPhysicsMaterial.name + " (Instance)")
    1680.                     _groundMaterial = GroundMaterial.Asphalt;
    1681.             }if(grassPhysicsMaterial){
    1682.                 if(wheelhit.collider.material.name == grassPhysicsMaterial.name + " (Instance)")
    1683.                     _groundMaterial = GroundMaterial.Grass;
    1684.             }if(sandPhysicsMaterial){
    1685.                 if(wheelhit.collider.material.name == sandPhysicsMaterial.name + " (Instance)")
    1686.                     _groundMaterial = GroundMaterial.Sand;
    1687.  
    1688.             }if(UseTerrainSplatMapForGroundPhysics){
    1689.  
    1690.                 if(wheelhit.collider.material.name == terrainPhysicsMaterial.name + " (Instance)"){
    1691.  
    1692.                     if(TerrainSurface.GetTextureMix(RearLeftWheelCollider.transform.position)[terrainSplatMapAsphaltIndex] > .5f){
    1693.                         _groundMaterial = GroundMaterial.Asphalt;
    1694.                     }else if(TerrainSurface.GetTextureMix(RearLeftWheelCollider.transform.position)[terrainSplatMapGrassIndex] > .5f){
    1695.                         _groundMaterial = GroundMaterial.Grass;
    1696.                     }else if(TerrainSurface.GetTextureMix(RearLeftWheelCollider.transform.position)[terrainSplatMapSandIndex] > .5f){
    1697.                         _groundMaterial = GroundMaterial.Sand;
    1698.                     }else{
    1699.                         _groundMaterial = GroundMaterial.Asphalt;
    1700.                     }
    1701.  
    1702.                 }else{
    1703.                     _groundMaterial = GroundMaterial.Asphalt;
    1704.                 }
    1705.  
    1706.             }else{
    1707.                 _groundMaterial = GroundMaterial.Asphalt;
    1708.             }
    1709.  
    1710.         }
    1711.  
    1712.         if(_groundMaterial == GroundMaterial.Asphalt)
    1713.             SkidSound(asphaltSkidClip);
    1714.         else if(_groundMaterial == GroundMaterial.Grass)
    1715.             SkidSound(grassSkidClip);
    1716.         else if(_groundMaterial == GroundMaterial.Sand)
    1717.             SkidSound(sandSkidClip);
    1718.  
    1719.     }
    1720.  
    1721.     public void SkidSound(AudioClip clip){
    1722.  
    1723.         for(int i = 0; i < allWheelColliders.Length; i++){
    1724.  
    1725.             WheelHit CorrespondingGroundHit;
    1726.             allWheelColliders[i].GetGroundHit(out CorrespondingGroundHit);
    1727.  
    1728.             if(skidSound.clip != clip){
    1729.                 skidSound.clip = clip;
    1730.             }
    1731.  
    1732.             if(Mathf.Abs(CorrespondingGroundHit.sidewaysSlip) > .25f || Mathf.Abs(CorrespondingGroundHit.forwardSlip) > (clip == sandSkidClip || clip == grassSkidClip ? 0f : .35f)){
    1733.                 if(rigid.velocity.magnitude > 1f){
    1734.                     skidSound.volume = Mathf.Lerp(
    1735.                         skidSound.volume,
    1736.                         Mathf.Clamp((Mathf.Abs(CorrespondingGroundHit.sidewaysSlip)) + (clip == sandSkidClip || clip == grassSkidClip ? speed / 100f : Mathf.Abs(CorrespondingGroundHit.forwardSlip)), 0f, maxSkidSoundVolume),
    1737.                         Time.deltaTime * 30f
    1738.                         );
    1739.                 }else{
    1740.                     skidSound.volume -= Time.deltaTime * 1.5f;
    1741.                 }
    1742.                 if(!skidSound.isPlaying)
    1743.                     skidSound.Play();
    1744.             }else{
    1745.                 skidSound.volume -= Time.deltaTime * 1.5f;
    1746.                 if(skidSound.volume < .05f && skidSound.isPlaying)
    1747.                     skidSound.Stop();
    1748.             }
    1749.  
    1750.         }
    1751.  
    1752.     }
    1753.    
    1754.     public void ResetCar (){
    1755.        
    1756.         if(speed < 5 && !rigid.isKinematic){
    1757.            
    1758.             if(transform.eulerAngles.z < 300 && transform.eulerAngles.z > 60){
    1759.                 resetTime += Time.deltaTime;
    1760.                 if(resetTime > 3){
    1761.                     transform.rotation = Quaternion.identity;
    1762.                     transform.position = new Vector3(transform.position.x, transform.position.y + 3, transform.position.z);
    1763.                     resetTime = 0f;
    1764.                 }
    1765.             }
    1766.            
    1767.             if(transform.eulerAngles.x < 300 && transform.eulerAngles.x > 60){
    1768.                 resetTime += Time.deltaTime;
    1769.                 if(resetTime > 3){
    1770.                     transform.rotation = Quaternion.identity;
    1771.                     transform.position = new Vector3(transform.position.x, transform.position.y + 3, transform.position.z);
    1772.                     resetTime = 0f;
    1773.                 }
    1774.             }
    1775.            
    1776.         }
    1777.        
    1778.     }
    1779.    
    1780.     void OnCollisionEnter (Collision collision){
    1781.        
    1782.         if (collision.contacts.Length < 1 || collision.relativeVelocity.magnitude < minimumCollisionForce)
    1783.             return;
    1784.  
    1785.             if(crashClips.Length > 0){
    1786.                 if (collision.contacts[0].thisCollider.gameObject.transform != transform.parent){
    1787.                     crashSound = RCCCreateAudioSource.NewAudioSource(gameObject, "Crash Sound AudioSource", 5, 20, maxCrashSoundVolume, crashClips[UnityEngine.Random.Range(0, crashClips.Length)], false, true, true);
    1788.                 }
    1789.             }
    1790.  
    1791.         if(useDamage){
    1792.  
    1793.             CollisionParticles(collision.contacts[0].point);
    1794.            
    1795.             Vector3 colRelVel = collision.relativeVelocity;
    1796.             colRelVel *= 1f - Mathf.Abs(Vector3.Dot(transform.up,collision.contacts[0].normal));
    1797.            
    1798.             float cos = Mathf.Abs(Vector3.Dot(collision.contacts[0].normal, colRelVel.normalized));
    1799.  
    1800.             if (colRelVel.magnitude * cos >= minimumCollisionForce){
    1801.                
    1802.                 sleep = false;
    1803.                
    1804.                 localVector = transform.InverseTransformDirection(colRelVel) * (damageMultiplier / 50f);
    1805.  
    1806.                 if (originalMeshData == null)
    1807.                     LoadOriginalMeshData();
    1808.  
    1809.                 if (DeformationEnabled)
    1810.                 {
    1811.                     for (int i = 0; i < deformableMeshFilters.Length; i++)
    1812.                     {
    1813.                         DeformMesh(deformableMeshFilters[i].mesh, originalMeshData[i].meshVerts, collision, cos, deformableMeshFilters[i].transform, rot);
    1814.                     }
    1815.                 }
    1816.                
    1817.             }
    1818.  
    1819.         }
    1820.  
    1821.     }
    1822.    
    1823.     public void Chassis (){
    1824.  
    1825.         if(sleepingRigid)
    1826.             return;
    1827.  
    1828.         if(rigid.centerOfMass != transform.InverseTransformPoint(COM.transform.position))
    1829.             rigid.centerOfMass = transform.InverseTransformPoint(COM.transform.position);
    1830.  
    1831.         verticalLean = Mathf.Clamp(Mathf.Lerp (verticalLean, rigid.angularVelocity.x * chassisVerticalLean, Time.deltaTime * 3f), -3.0f, 3.0f);
    1832.  
    1833.         WheelHit CorrespondingGroundHit;
    1834.         RearRightWheelCollider.GetGroundHit(out CorrespondingGroundHit);
    1835.  
    1836.         float normalizedLeanAngle = Mathf.Clamp(CorrespondingGroundHit.sidewaysSlip, -1f, 1f);
    1837.  
    1838.         if(normalizedLeanAngle >= 0f)
    1839.             normalizedLeanAngle = 1;
    1840.         else
    1841.             normalizedLeanAngle = -1;
    1842.  
    1843.         if(transform.InverseTransformDirection(rigid.velocity).z >= 0)
    1844.             horizontalLean = Mathf.Clamp(Mathf.Lerp (horizontalLean, (transform.InverseTransformDirection(rigid.angularVelocity).y) * chassisHorizontalLean, Time.deltaTime * 3f), -3f, 3f);
    1845.         else
    1846.             horizontalLean = Mathf.Clamp(Mathf.Lerp (horizontalLean, (Mathf.Abs (transform.InverseTransformDirection(rigid.angularVelocity).y) * -normalizedLeanAngle) * chassisHorizontalLean, Time.deltaTime * 3f), -3.0f, 3.0f);
    1847.  
    1848.         if(float.IsNaN(verticalLean) || float.IsNaN(horizontalLean) || float.IsInfinity(verticalLean) || float.IsInfinity(horizontalLean) || Mathf.Approximately(verticalLean, 0f) || Mathf.Approximately(horizontalLean, 0f))
    1849.             return;
    1850.  
    1851.         Quaternion target = Quaternion.Euler(verticalLean, chassis.transform.localRotation.y + (rigid.angularVelocity.z), horizontalLean);
    1852.         chassis.transform.localRotation = target;
    1853.  
    1854.     }
    1855.    
    1856.     public void Lights (){
    1857.  
    1858.         if(brakeInput > .1f){
    1859.             brakeLightInput = Mathf.Lerp(brakeLightInput, 1f, Time.deltaTime * 50f);
    1860.         }else{
    1861.             if(!headLightsOn)
    1862.                 brakeLightInput = Mathf.Lerp(brakeLightInput, 0f, Time.deltaTime * 50f);
    1863.             else
    1864.                 brakeLightInput = Mathf.Lerp(brakeLightInput, .3f, Time.deltaTime * 50f);
    1865.         }
    1866.  
    1867.         if(Input.GetKeyDown(KeyCode.L) && !AIController){
    1868.             headLightsOn = !headLightsOn;
    1869.         }
    1870.        
    1871.         for(int i = 0; i < brakeLights.Length; i++){
    1872.            
    1873.             if(!reverseGear){
    1874.                 brakeLights[i].intensity = brakeLightInput;
    1875.             }else{
    1876.                 if(!headLightsOn)
    1877.                     brakeLights[i].intensity = 0f;
    1878.                 else
    1879.                     brakeLights[i].intensity = Mathf.Lerp(brakeLights[i].intensity, .3f, Time.deltaTime * 50f);
    1880.             }
    1881.  
    1882.         }
    1883.        
    1884.         for(int i = 0; i < headLights.Length; i++){
    1885.            
    1886.             if(headLightsOn)
    1887.                 headLights[i].enabled = true;
    1888.             else
    1889.                 headLights[i].enabled = false;
    1890.            
    1891.         }
    1892.        
    1893.         for(int i = 0; i < reverseLights.Length; i++){
    1894.            
    1895.             if(!reverseGear)
    1896.                 reverseLights[i].intensity = Mathf.Lerp (reverseLights[i].intensity, 0f, Time.deltaTime * 50f);
    1897.             else
    1898.                 reverseLights[i].intensity = brakeLightInput;
    1899.            
    1900.         }
    1901.        
    1902.     }
    1903.    
    1904.     void OnGUI (){
    1905.  
    1906.         if(demoGUI){
    1907.  
    1908.             GUI.skin.label.fontSize = 12;
    1909.             GUI.skin.box.fontSize = 12;
    1910.            
    1911.             GUI.backgroundColor = Color.gray;
    1912.             float guiWidth = Screen.width / 2f;
    1913.            
    1914.             GUI.Box(new Rect(Screen.width - 400 - guiWidth, 10, 800, 270), "");
    1915.            
    1916.             GUI.Label(new Rect(Screen.width - 390 - guiWidth, 10, 400, 150), "Engine RPM : " + Mathf.CeilToInt(engineRPM));
    1917.             GUI.Label(new Rect(Screen.width - 200 - guiWidth, 10, 400, 150), "Engine Running : " + (engineRunning == true ? "Running" : "Stopped").ToString());
    1918.             GUI.Label(new Rect(Screen.width - 200 - guiWidth, 30, 400, 150), "Engine Starter : " + (engineStarting == true ? "Starting" : "Stopped").ToString());
    1919.            
    1920.             GUI.Label(new Rect(Screen.width - 200 - guiWidth, 90, 400, 150), "Engine Sound On Volume: " + engineSoundOn.volume.ToString("F1"));
    1921.             GUI.Label(new Rect(Screen.width - 200 - guiWidth, 110, 400, 150), "Engine Sound On Pitch: " + engineSoundOn.pitch.ToString("F1"));
    1922.             GUI.Label(new Rect(Screen.width - 200 - guiWidth, 130, 400, 150), "Engine Sound Off Volume: " + engineSoundOff.volume.ToString("F1"));
    1923.             GUI.Label(new Rect(Screen.width - 200 - guiWidth, 150, 400, 150), "Engine Sound Off Pitch: " + engineSoundOff.pitch.ToString("F1"));
    1924.  
    1925.  
    1926.            
    1927.             GUI.Label(new Rect(Screen.width - 390 - guiWidth, 30, 400, 150), "Speed (KM/H) : " + Mathf.CeilToInt(speed));
    1928.             GUI.Label(new Rect(Screen.width - 390 - guiWidth, 50, 400, 150), "Steer Angle : " + Mathf.CeilToInt(FrontLeftWheelCollider.steerAngle));
    1929.             GUI.Label(new Rect(Screen.width - 390 - guiWidth, 70, 400, 150), "Automatic Shifting : " + (automaticGear == true ? "Automatic" : "Manual").ToString());
    1930.  
    1931.             if(!changingGear)
    1932.                 GUI.Label(new Rect(Screen.width - 390 - guiWidth, 90, 400, 150), "Gear No : " + (reverseGear != true ? (currentGear + 1).ToString() : "R").ToString());
    1933.             else
    1934.                 GUI.Label(new Rect(Screen.width - 390 - guiWidth, 90, 400, 150), "Gear No : " + "N");  
    1935.            
    1936.             GUI.Label(new Rect(Screen.width - 390 - guiWidth, 230, 400, 150), "Mobile Horizontal Tilt : " + Input.acceleration.x);
    1937.             GUI.Label(new Rect(Screen.width - 390 - guiWidth, 250, 400, 150), "Mobile Vertical Tilt : " + Input.acceleration.y);
    1938.            
    1939.             //Front Wheels
    1940.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 10, 400, 150), "Front Left Wheel RPM : " + Mathf.CeilToInt(FrontLeftWheelCollider.rpm));
    1941.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 10, 400, 150), "Front Right Wheel RPM : " + Mathf.CeilToInt(FrontRightWheelCollider.rpm));
    1942.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 30, 400, 150), "Front Left Wheel Torque : " + Mathf.CeilToInt(FrontLeftWheelCollider.motorTorque));
    1943.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 30, 400, 150), "Front Right Wheel Torque : " + Mathf.CeilToInt(FrontRightWheelCollider.motorTorque));
    1944.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 50, 400, 150), "Front Left Wheel brake : " + Mathf.CeilToInt(FrontLeftWheelCollider.brakeTorque));
    1945.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 50, 400, 150), "Front Right Wheel brake : " + Mathf.CeilToInt(FrontRightWheelCollider.brakeTorque));
    1946.            
    1947.             WheelHit hit;
    1948.             FrontLeftWheelCollider.GetGroundHit(out hit);
    1949.  
    1950.             GUI.Label(new Rect(Screen.width - 200 - guiWidth, 190, 400, 150), "Speed: " + speed);
    1951.             GUI.Label(new Rect(Screen.width - 200 - guiWidth, 210, 400, 150), "WCSpeed: " + wheelRPMToSpeed);
    1952.            
    1953.             if(FrontLeftWheelCollider.GetGroundHit(out hit)){
    1954.                 GUI.Label(new Rect(Screen.width - 200 - guiWidth, 50, 400, 150), "Ground Material : " + _groundMaterial.ToString());
    1955.                 GUI.Label(new Rect(Screen.width - 200 - guiWidth, 70, 400, 150), "Ground Grip : " + FrontLeftWheelCollider.forwardFriction.stiffness);
    1956.             }
    1957.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 70, 400, 150), "Front Left Wheel Force : " + Mathf.CeilToInt(hit.force));
    1958.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 90, 400, 150), "Front Left Wheel Sideways Grip : " + (1 - Mathf.Abs(hit.sidewaysSlip)).ToString("F2"));
    1959.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 110, 400, 150), "Front Left Wheel Forward Grip : " + (1 - Mathf.Abs(hit.forwardSlip)).ToString("F2"));
    1960.            
    1961.             FrontRightWheelCollider.GetGroundHit(out hit);
    1962.            
    1963.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 70, 400, 150), "Front Right Wheel Force : " + Mathf.CeilToInt(hit.force));
    1964.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 90, 400, 150), "Front Right Wheel Sideways Grip : " + (1 - Mathf.Abs(hit.sidewaysSlip)).ToString("F2"));
    1965.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 110, 400, 150), "Front Right Wheel Forward Grip : " +(1 - Mathf.Abs(hit.forwardSlip)).ToString("F2"));
    1966.            
    1967.             GUI.Label(new Rect(Screen.width - 390 - guiWidth, 170, 400, 150), "ABS: " + ABS + ". Current State: " + (ABSAct == true ? "Engaged" : "Safe").ToString());
    1968.             GUI.Label(new Rect(Screen.width - 390 - guiWidth, 190, 400, 150), "TCS: " + TCS + ". Current State: " + (TCSAct == true ? "Engaged" : "Safe").ToString());
    1969.             GUI.Label(new Rect(Screen.width - 390 - guiWidth, 210, 400, 150), "ESP: " + ESP + ". Current State: " + (ESPAct == true ? "Engaged" : "Safe").ToString());
    1970.            
    1971.             //Rear Wheels
    1972.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 150, 400, 150), "Rear Left Wheel RPM : " + Mathf.CeilToInt(RearLeftWheelCollider.rpm));
    1973.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 150, 400, 150), "Rear Right Wheel RPM : " + Mathf.CeilToInt(RearRightWheelCollider.rpm));
    1974.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 170, 400, 150), "Rear Left Wheel Torque : " + Mathf.CeilToInt(RearLeftWheelCollider.motorTorque));
    1975.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 170, 400, 150), "Rear Right Wheel Torque : " + Mathf.CeilToInt(RearRightWheelCollider.motorTorque));
    1976.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 190, 400, 150), "Rear Left Wheel brake : " + Mathf.CeilToInt(RearLeftWheelCollider.brakeTorque));
    1977.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 190, 400, 150), "Rear Right Wheel brake : " + Mathf.CeilToInt(RearRightWheelCollider.brakeTorque));
    1978.            
    1979.             RearLeftWheelCollider.GetGroundHit(out hit);
    1980.            
    1981.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 210, 400, 150), "Rear Left Wheel Force : " + Mathf.CeilToInt(hit.force));
    1982.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 230, 400, 150), "Rear Left Wheel Sideways Grip : " + (1 - Mathf.Abs(hit.sidewaysSlip)).ToString("F2"));
    1983.             GUI.Label(new Rect(Screen.width + 00 - guiWidth, 250, 400, 150), "Rear Left Wheel Forward Grip : " + (1 - Mathf.Abs(hit.forwardSlip)).ToString("F2"));
    1984.            
    1985.             RearRightWheelCollider.GetGroundHit(out hit);
    1986.            
    1987.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 210, 400, 150), "Rear Right Wheel Force : " + Mathf.CeilToInt(hit.force));
    1988.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 230, 400, 150), "Rear Right Wheel Sideways Grip : " + (1 - Mathf.Abs(hit.sidewaysSlip)).ToString("F2"));
    1989.             GUI.Label(new Rect(Screen.width + 200 - guiWidth, 250, 400, 150), "Rear Right Wheel Forward Grip : " + (1 - Mathf.Abs(hit.forwardSlip)).ToString("F2"));
    1990.            
    1991.             GUI.backgroundColor = Color.green;
    1992.             GUI.Button (new Rect(Screen.width-20 - guiWidth, 260, 10, Mathf.Clamp((-gasInput * 100), -100, 0)), "");
    1993.            
    1994.             GUI.backgroundColor = Color.red;
    1995.             GUI.Button (new Rect(Screen.width-35 - guiWidth, 260, 10, Mathf.Clamp((-brakeInput * 100), -100, 0)), "");
    1996.            
    1997.             GUI.backgroundColor = Color.blue;
    1998.             GUI.Button (new Rect(Screen.width-50 - guiWidth, 260, 10, Mathf.Clamp((-clutchInput * 100), -100, 0)), "");
    1999.            
    2000.         }
    2001.        
    2002.         if(canControl){
    2003.            
    2004.             if(useAccelerometerForSteer && mobileController){
    2005.  
    2006.                 if(_mobileControllerType == MobileGUIType.NGUIController){
    2007.                     if(leftArrowNGUI){
    2008.                         if(leftArrowNGUI.gameObject.activeSelf)
    2009.                             leftArrowNGUI.gameObject.SetActive(false);
    2010.                     }
    2011.                     if(rightArrowNGUI){
    2012.                         if(rightArrowNGUI.gameObject.activeSelf)
    2013.                             rightArrowNGUI.gameObject.SetActive(false);
    2014.                     }
    2015.                     if(handbrakeNGUI){
    2016.                         if(!handbrakeNGUI.gameObject.activeSelf)
    2017.                             handbrakeNGUI.gameObject.SetActive(true);
    2018.                     }
    2019.                     if(brakePedalNGUI){
    2020.                         brakePedalNGUI.transform.position = leftArrowNGUI.transform.position;
    2021.                     }
    2022.                 }
    2023.  
    2024.                 if(_mobileControllerType == MobileGUIType.UIController){
    2025.                     if(leftArrowUI){
    2026.                         if(leftArrowUI.gameObject.activeSelf)
    2027.                             leftArrowUI.gameObject.SetActive(false);
    2028.                     }
    2029.                     if(rightArrowUI){
    2030.                         if(rightArrowUI.gameObject.activeSelf)
    2031.                             rightArrowUI.gameObject.SetActive(false);
    2032.                     }
    2033.                     if(handbrakeUI){
    2034.                         if(!handbrakeUI.gameObject.activeSelf)
    2035.                             handbrakeUI.gameObject.SetActive(true);
    2036.                     }
    2037.                     if(brakePedalUI){
    2038.                         brakePedalUI.transform.position = leftArrowUI.transform.position;
    2039.                     }
    2040.                 }
    2041.  
    2042.                 steeringWheelControl = false;
    2043.  
    2044.             }else if(mobileController){
    2045.  
    2046.                 if(_mobileControllerType == MobileGUIType.NGUIController){
    2047.  
    2048.                     if(gasPedalNGUI){
    2049.                         if(!gasPedalNGUI.gameObject.activeSelf)
    2050.                             gasPedalNGUI.gameObject.SetActive(true);
    2051.                     }
    2052.                     if(brakePedalNGUI){
    2053.                         if(!brakePedalNGUI.gameObject.activeSelf)
    2054.                             brakePedalNGUI.gameObject.SetActive(true);
    2055.                     }
    2056.                     if(leftArrowNGUI){
    2057.                         if(!leftArrowNGUI.gameObject.activeSelf)
    2058.                             leftArrowNGUI.gameObject.SetActive(true);
    2059.                     }
    2060.                     if(rightArrowNGUI){
    2061.                         if(!rightArrowNGUI.gameObject.activeSelf)
    2062.                             rightArrowNGUI.gameObject.SetActive(true);
    2063.                     }
    2064.                     if(handbrakeNGUI){
    2065.                         if(!handbrakeNGUI.gameObject.activeSelf)
    2066.                             handbrakeNGUI.gameObject.SetActive(true);
    2067.                     }
    2068.                     if(brakePedalNGUI){
    2069.                         brakePedalNGUI.transform.position = defbrakePedalPosition;
    2070.                     }
    2071.  
    2072.                 }
    2073.  
    2074.                 if(_mobileControllerType == MobileGUIType.UIController){
    2075.  
    2076.                     if(gasPedalUI){
    2077.                         if(!gasPedalUI.gameObject.activeSelf)
    2078.                             gasPedalUI.gameObject.SetActive(true);
    2079.                     }
    2080.                     if(brakePedalUI){
    2081.                         if(!brakePedalUI.gameObject.activeSelf)
    2082.                             brakePedalUI.gameObject.SetActive(true);
    2083.                     }
    2084.                     if(leftArrowUI){
    2085.                         if(!leftArrowUI.gameObject.activeSelf)
    2086.                             leftArrowUI.gameObject.SetActive(true);
    2087.                     }
    2088.                     if(rightArrowUI){
    2089.                         if(!rightArrowUI.gameObject.activeSelf)
    2090.                             rightArrowUI.gameObject.SetActive(true);
    2091.                     }
    2092.                     if(handbrakeUI){
    2093.                         if(!handbrakeUI.gameObject.activeSelf)
    2094.                             handbrakeUI.gameObject.SetActive(true);
    2095.                     }
    2096.                     if(brakePedalUI){
    2097.                         brakePedalUI.transform.position = defbrakePedalPosition;
    2098.                     }
    2099.                 }
    2100.  
    2101.             }
    2102.            
    2103.             if(steeringWheelControl && mobileController){
    2104.  
    2105.                 if(_mobileControllerType == MobileGUIType.NGUIController){
    2106.                     if(leftArrowNGUI){
    2107.                         if(leftArrowNGUI.gameObject.activeSelf)
    2108.                             leftArrowNGUI.gameObject.SetActive(false);
    2109.                     }
    2110.                     if(rightArrowNGUI){
    2111.                         if(rightArrowNGUI.gameObject.activeSelf)
    2112.                             rightArrowNGUI.gameObject.SetActive(false);
    2113.                     }
    2114.                 }
    2115.  
    2116.                 if(_mobileControllerType == MobileGUIType.UIController){
    2117.                     if(leftArrowUI){
    2118.                         if(leftArrowUI.gameObject.activeSelf)
    2119.                             leftArrowUI.gameObject.SetActive(false);
    2120.                     }
    2121.                     if(rightArrowUI){
    2122.                         if(rightArrowUI.gameObject.activeSelf)
    2123.                             rightArrowUI.gameObject.SetActive(false);
    2124.                     }
    2125.                 }
    2126.  
    2127.             }
    2128.  
    2129.             if(showMobileControllerChangerButtons && canControl){
    2130.                
    2131.                 if(GUI.Button(new Rect(Screen.width - 275, Screen.height / 2 - 35, 250, 50), "Use Accelerometer \n For Steer")){
    2132.                     useAccelerometerForSteer = !useAccelerometerForSteer;
    2133.                 }
    2134.                
    2135.                 if(GUI.Button(new Rect(Screen.width - 275, Screen.height / 2 + 35, 250, 50), "Use Steering Wheel \n For Steer")){
    2136.                     steeringWheelControl = !steeringWheelControl;
    2137.                 }
    2138.                
    2139.             }
    2140.  
    2141.         }
    2142.        
    2143.     }
    2144.  
    2145.     private bool OverTorque(){
    2146.  
    2147.         if(speed > maxspeed || !engineRunning)
    2148.             return true;
    2149.        
    2150.         if(reverseGear && speed > 55)
    2151.             return true;
    2152.        
    2153.         if(!engineRunning)
    2154.             return true;
    2155.  
    2156.         return false;
    2157.  
    2158.     }
    2159.  
    2160.     void OnDrawGizmos(){
    2161. #if UNITY_EDITOR
    2162.         if(Application.isPlaying){
    2163.  
    2164.             WheelHit hit;
    2165.  
    2166.             for(int i = 0; i < allWheelColliders.Length; i++){
    2167.  
    2168.                 allWheelColliders[i].GetGroundHit(out hit);
    2169.  
    2170.                 Matrix4x4 temp = Gizmos.matrix;