Esempio n. 1
0
    private Vector3 CalculateCorrectionTorque()
    {
        var correctionTorque = CarBody.CalculateRequiredTorqueForRotation(castedOrientation, Time.fixedDeltaTime, maxCorrectionTorque);

        correctionTorque -= up * Vector3.Dot(correctionTorque, up);
        return(correctionTorque);
    }
Esempio n. 2
0
    private void ApplyFriction()
    {
        float currentHorVelocity         = Vector3.Dot(CarBody.velocity, right);
        float velocityFrictionMultiplier = frictionCurve.Evaluate(currentHorVelocity / maxSpeed);

        float forceToStop = PhysicsHelpers.CalculateRequiredForceForSpeed(CarBody.mass, currentHorVelocity, 0);

        CarBody.AddForce(right * forceToStop * velocityFrictionMultiplier, ForceMode.Force);

        Vector3 correctionTorque         = CarBody.CalculateRequiredTorqueForRotation(castedOrientation, Time.fixedDeltaTime, maxCorrectionTorque);
        float   maxTorque                = 20;
        float   correctionTorqueAmount   = Vector3.Dot(correctionTorque, up);
        float   torqueFrictionMultiplier = frictionCurve.Evaluate(correctionTorqueAmount / maxTorque);

        CarBody.AddTorque(up * correctionTorqueAmount, ForceMode.Force);
    }