void checkWheelAntiRoll(WheelsPare wheelPare, float antiRollForce) { travelL = 1.0f; travelR = 1.0f; groundedL = wheelPare.leftWheel.wheelCollider.GetGroundHit(out hit); if (groundedL) { travelL = (-car.transform.InverseTransformPoint(hit.point).y - wheelPare.leftWheel.wheelCollider.radius) / wheelPare.leftWheel.wheelCollider.suspensionDistance; } groundedR = wheelPare.rightWheel.wheelCollider.GetGroundHit(out hit); if (groundedR) { travelR = (-car.transform.InverseTransformPoint(hit.point).y - wheelPare.rightWheel.wheelCollider.radius) / wheelPare.rightWheel.wheelCollider.suspensionDistance; } antiRollForce = (travelL - travelR) * antiRollForce; if (groundedL) { car._rigidbody.AddForceAtPosition(car.transform.up * -antiRollForce, wheelPare.leftWheel.wheelCollider.transform.position); } if (groundedR) { car._rigidbody.AddForceAtPosition(car.transform.up * antiRollForce, wheelPare.rightWheel.wheelCollider.transform.position); } }
void Start() { frontWheelPare = new WheelsPare(car.frontWheels); backWheelPare = new WheelsPare(car.backWheels); }