Example #1
0
    private void CalculateSteering()
    {
        float steeringSpeeed = steeringSpeedCurve.Evaluate(_currentSpeedKmH);


        float angleDeg = steeringSpeeed * steeringInput;



        float angleRad = Mathf.Min(Mathf.Abs(angleDeg), maxSteeringAngle) * Mathf.Sign(angleDeg) * Mathf.Deg2Rad;

        float axleSeprationLength = Vector3.Distance(frontAxle.offset, rearAxle.offset);

        float wheelSeparationLength = Vector3.Distance(frontAxle.Get_LeftPoint(), frontAxle.Get_RightPoint());



        float radius = axleSeprationLength * (1 / Mathf.Tan(angleRad));

        frontAxle.leftWheel.yRad  = Mathf.Atan(axleSeprationLength / (radius + wheelSeparationLength * .5f));
        frontAxle.rightWheel.yRad = Mathf.Atan(axleSeprationLength / (radius - wheelSeparationLength * .5f));
    }