Beispiel #1
0
        static LinePath ToLinePath(List <Vector3> path)
        {
            LinePath lp = null;

            if (path != null)
            {
                lp = new LinePath(path);
            }

            return(lp);
        }
Beispiel #2
0
        /// <summary>
        /// Will return true if the character is at the end of the given path
        /// </summary>
        public bool IsAtEndOfPath(LinePath path)
        {
            /* If the path has only one node then just check the distance to that node. */
            if (path.Length == 1)
            {
                return(Vector2.Distance(rb.position, path[0]) < stopRadius);
            }
            /* Else see if the character is at the end of the path. */
            else
            {
                Vector2 finalDestination;

                /* Get the param for the closest position point on the path given the character's position */
                float param = path.GetParam(transform.position);

                return(IsAtEndOfPath(path, param, out finalDestination));
            }
        }
Beispiel #3
0
        private bool IsAtEndOfPath(LinePath path, float param, out Vector2 finalDestination)
        {
            bool result;

            /* Find the final destination of the character on this path */
            finalDestination = (pathDirection > 0) ? path[path.Length - 1] : path[0];

            /* If the param is closest to the last segment then check if we are at the final destination */
            if (param >= path.distances[path.Length - 2])
            {
                result = Vector2.Distance(rb.position, finalDestination) < stopRadius;
            }
            /* Else we are not at the end of the path */
            else
            {
                result = false;
            }

            return(result);
        }