public GetTrackDirection ( float t ) : Vector3 | ||
t | float | |
Результат | Vector3 |
private void UpdateCalculations(bool initalCalculation) { if (target == null) { return; } Vector3 targetPosition = target.position; foreach (BoxCollider area in noTrackingAreas) { if (area.bounds.Contains(targetPosition)) { insideIgnore = true; return; } } if (insideIgnore) { insideIgnore = false; initalCalculation = true; } float trackLength = track.trackLength; float trackSearchPoints = trackLength / 10.0f; float trackSearchIncrement = 1.0f / trackSearchPoints; float nearestSqrDistance = Mathf.Infinity; float newNearestPercent = 0; Vector3 newNearestPosition = targetPosition; for (float i = 0; i < 1.0f; i += trackSearchIncrement) { Vector3 serachPoint = track.GetTrackPosition(i); Vector3 searchDifference = serachPoint - targetPosition; float searchSqrDist = Vector3.SqrMagnitude(searchDifference); if (searchSqrDist < nearestSqrDistance) { nearestSqrDistance = searchSqrDist; newNearestPercent = i; newNearestPosition = serachPoint; } } float calculatedDistance = Vector3.Distance(targetPosition, newNearestPosition); if (calculatedDistance > maxDistance && !initalCalculation) { return; } float percentAdvance = Mathf.Abs(nearestPercent - newNearestPercent); if (percentAdvance > 0.1f && percentAdvance < 0.9f && !initalCalculation) { ResetTarget(); return; } float distanceFromTrack = Vector3.Distance(targetPosition, newNearestPosition); if (distanceFromTrack > resetDistance) { ResetTarget(); return; } nearestPercent = newNearestPercent; nearestPostion = newNearestPosition; nearestDirection = track.GetTrackDirection(nearestPercent); }