Esempio n. 1
0
        /// Finds the distance along the path that is closest to the given point
        public float GetClosestDistanceAlongPath(Vector3 worldPoint)
        {
            Vector3 localPoint = MathUtility.InverseTransformPoint(worldPoint, transformPosition, transformRotation, transformLossyScale, space);

            VertexPath.TimeOnPathData data = CalculateClosestPointOnPathData(localPoint);
            return(Mathf.Lerp(cumulativeLengthAtEachVertex[data.previousIndex], cumulativeLengthAtEachVertex[data.nextIndex], data.percentBetweenIndices));
        }
Esempio n. 2
0
        /// Finds the closest point on the path from any point in the world
        public Vector3 GetClosestPointOnPath(Vector3 worldPoint)
        {
            // Transform the provided worldPoint into VertexPath local-space.
            // This allows to do math on the localPoint's, thus avoiding the need to
            // transform each local vertexpath point into world space via GetPoint.
            Vector3 localPoint = MathUtility.InverseTransformPoint(worldPoint, transformPosition, transformRotation, transformLossyScale, space);

            VertexPath.TimeOnPathData data = CalculateClosestPointOnPathData(localPoint);
            Vector3 localResult            = Vector3.Lerp(localPoints[data.previousIndex], localPoints[data.nextIndex], data.percentBetweenIndices);

            // Transform local result into world space
            return(MathUtility.TransformPoint(localResult, transformPosition, transformRotation, transformLossyScale, space));
        }