extract function

This commit is contained in:
in0finite 2021-02-04 23:17:12 +01:00
parent f6fe21cbdb
commit b0ec6417c7

View file

@ -486,15 +486,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
wheel.Child.transform.localPosition = position; wheel.Child.transform.localPosition = position;
// reset the yaw UpdateWheelRotation(wheel, wheel.Collider.rpm, wheel.Collider.steerAngle);
wheel.Child.localRotation = wheel.Roll;
// calculate new roll
wheel.Child.Rotate(wheel.IsLeftHand ? Vector3.left : Vector3.right, wheel.Collider.rpm / 60.0f * 360.0f * Time.deltaTime);
wheel.Roll = wheel.Child.localRotation;
// apply yaw
wheel.Child.localRotation = Quaternion.AngleAxis(wheel.Collider.steerAngle, Vector3.up) * wheel.Roll;
} }
if (_colorsChanged) if (_colorsChanged)
@ -516,6 +508,19 @@ namespace SanAndreasUnity.Behaviours.Vehicles
PhysicsFixedUpdate(); PhysicsFixedUpdate();
} }
public static void UpdateWheelRotation(Wheel wheel, float rpm, float steerAngle)
{
// reset the yaw
wheel.Child.localRotation = wheel.Roll;
// calculate new roll
wheel.Child.Rotate(wheel.IsLeftHand ? Vector3.left : Vector3.right, rpm / 60.0f * 360.0f * Time.deltaTime);
wheel.Roll = wheel.Child.localRotation;
// apply yaw
wheel.Child.localRotation = Quaternion.AngleAxis(steerAngle, Vector3.up) * wheel.Roll;
}
void UpdateHighDetailMeshes() void UpdateHighDetailMeshes()
{ {
this.HighDetailMeshesParent.SetPositionAndRotation(this.transform.position, this.transform.rotation); this.HighDetailMeshesParent.SetPositionAndRotation(this.transform.position, this.transform.rotation);