void CalculateEnginePower(Vector3 relativeVelocity) { if (throttle == 0) { currentEnginePower -= Time.deltaTime * 1000; } else if (Utilitys.HaveTheSameSign(relativeVelocity.z, throttle)) { float normPower = (currentEnginePower / engineForceValues[engineForceValues.Length - 1]) * 2; currentEnginePower += Time.deltaTime * 200 * Utilitys.EvaluateNormPower(normPower); } else { currentEnginePower -= Time.deltaTime * 300; } if (currentGear == 0) { currentEnginePower = Mathf.Clamp(currentEnginePower, 0, engineForceValues[0]); } else { currentEnginePower = Mathf.Clamp(currentEnginePower, engineForceValues[currentGear - 1], engineForceValues[currentGear]); } }
void ApplyThrottle(Vector3 relativeVelocity) { if (canDrive) { float throttleForce = 0; float brakeForce = 0; if (Utilitys.HaveTheSameSign(relativeVelocity.z, throttle)) { throttleForce = throttle * currentEnginePower * carRigidbody.mass; } else { brakeForce = throttle * engineForceValues[0] * carRigidbody.mass; } carRigidbody.AddForce(carTransform.forward * Time.deltaTime * (throttleForce + brakeForce)); } }