using UnityEngine; using System.Collections; public class car_Control : MonoBehaviour { public GameObject forcePoint; public Suspension[] supensions; //public Suspension supFR; //public Suspension supFL; //public Suspension supBR; //public Suspension supBL; public float speed; public float torque; public float grip; public float driftGrip; private float curGrip; public Vector3 centreOfMass; public Rigidbody carRigid; // Use this for initialization void Start () { carRigid = GetComponent(); carRigid.centerOfMass = centreOfMass; } // Update is called once per frame void FixedUpdate () { carRigid.centerOfMass = centreOfMass; float inputX = Input.GetAxis ("Player1 Movement Y"); float inputY = Input.GetAxis("Player1 Movement X"); applyAcceleration (inputX); applyTorque (inputY); driftCheck (); applyGrip (); } void applyAcceleration(float input){ Vector3 force = transform.forward * input * speed; //Vector3 rayNormal = (supensions[0].supHit.normal + supensions[1].supHit.normal + supensions[2].supHit.normal + supensions[3].supHit.normal) / 4; Vector3 rayNormal = suspensionNormal (); rayNormal = Quaternion.AngleAxis(90, transform.right) * rayNormal; Vector3 projectedForce = Vector3.Project (force, rayNormal); //carRigid.AddForceAtPosition (projectedForce,forcePoint.transform.position); carRigid.AddForce(projectedForce); } void applyTorque (float input){ carRigid.AddTorque(transform.up * torque * input); } void driftCheck(){ if (Input.GetButton ("Player1 Jump")) { curGrip = driftGrip; } else { curGrip = grip; } } void applyGrip(){ float localVelX = transform.InverseTransformDirection(carRigid.velocity).x; bool grounded = false; for (int i = 0; i0) grounded = true; } Debug.Log ("Grounded: " + grounded); if (grounded) { for (int i = 0; i