public static SignedAngle ( Vector3 fromDirection, Vector3 toDirection, Vector3 referenceRight ) : float | ||
fromDirection | Vector3 | |
toDirection | Vector3 | |
referenceRight | Vector3 | |
Результат | float |
void UpdateWheelAlignment() { if (!wheelAlignmentTransform) { return; } if (HighLogic.LoadedSceneIsFlight && CurrentState == GearStates.Deployed) { bool wheelHit = false; Vector3 hitNormal = Vector3.zero; for (int i = 0; i < wheelColliders.Length; i++) { Vector3 rayOrigin = wheelColliders[i].transform.TransformPoint(wheelColliders[i].center); Vector3 rayDirection = -wheelColliders[i].transform.up; float rayDistance = wheelColliders[i].suspensionDistance + wheelColliders[i].radius + 0.35f; Ray ray = new Ray(rayOrigin, rayDirection); RaycastHit rayHit; if (Physics.Raycast(ray, out rayHit, rayDistance, 557057)) { wheelHit = true; hitNormal = rayHit.normal; break; } } if (wheelHit) { Vector3 projectedNormal = Vector3.ProjectOnPlane(hitNormal, wheelAlignmentTransform.right); Vector3 projectedReference = Vector3.ProjectOnPlane(wheelAlignmentTransform.parent.forward, wheelAlignmentTransform.right); float normalAngle = Utils.SignedAngle(projectedReference, projectedNormal, wheelAlignmentTransform.parent.up); Quaternion targetAngle = Quaternion.Euler(-normalAngle, 0, 0); wheelAlignmentTransform.localRotation = Quaternion.RotateTowards(wheelAlignmentTransform.localRotation, targetAngle, wheelAlignmentSpeed * TimeWarp.fixedDeltaTime); } else { Quaternion targetAngle = Quaternion.Euler(defaultWheelAlignment, 0, 0); wheelAlignmentTransform.localRotation = Quaternion.Lerp(wheelAlignmentTransform.localRotation, targetAngle, 5 * TimeWarp.fixedDeltaTime); } } else { wheelAlignmentTransform.localRotation = Quaternion.Lerp(wheelAlignmentTransform.localRotation, Quaternion.identity, 5 * TimeWarp.fixedDeltaTime); } }