/// <summary> /// Updates visuals for each axle on the vehicle /// </summary> private void ApplyLocalPositionToAxleVisuals() { foreach (var axle in vehicle.Axles) { Axle.UpdateVisuals(axle); } }
/// <summary> /// Sets the axle steer angle to an angle relative to the lerp timeframe /// </summary> /// <param name="axle"></param> private void LerpToSteerAngle(Axle axle) { float angle = Mathf.Lerp(axle.InitialLerpAngle, axle.TargetLerpAngle, axle.TimeSinceStartLerp); axle.Right.steerAngle = angle; axle.Left.steerAngle = angle; }
private void Start() { vehicle = GetComponent <Vehicle>(); foreach (Axle a in vehicle.Axles) { Axle.ConfigureVehicleSubsteps(a); } }
/// <summary> /// Recalculates wheel lerp variables based on the current targetLerpAngle of an axis /// </summary> /// <param name="axle"></param> private void RecalculateLerp(Axle axle) { if (axle.PreviousTargetLerpAngle != axle.TargetLerpAngle) // User has changed directions { axle.IsLerping = true; axle.TimeSinceStartLerp = 0; axle.InitialLerpAngle = axle.Right.steerAngle; axle.PreviousTargetLerpAngle = axle.TargetLerpAngle; } else if (axle.Right.steerAngle == axle.TargetLerpAngle) // Maximum steer angle has been reached { axle.IsLerping = false; } else // Axle is in the middle of lerping { axle.IsLerping = true; } }
public static void UpdateVisuals(Axle axle) { ApplyLocalPositionToVisuals(axle.Right); ApplyLocalPositionToVisuals(axle.Left); }
public static void InitAxleLerp(Axle axle, float initAngle) { axle.TargetLerpAngle = initAngle; axle.PreviousTargetLerpAngle = initAngle; axle.InitialLerpAngle = initAngle; }
/// <summary> /// Fix to stop wheel collider jitter at low speeds /// </summary> /// <see cref="http://answers.unity.com/answers/1084280/view.html"/> public static void ConfigureVehicleSubsteps(Axle axle) { axle.Right.ConfigureVehicleSubsteps(5, 12, 15); axle.Left.ConfigureVehicleSubsteps(5, 12, 15); }