Esempio n. 1
0
        public Vector3 GetSteering(LinePath path, bool pathLoop, out Vector3 targetPosition)
        {
            /* If the path has only one node then just go to that position. */
            if (path.Length == 1)
            {
                targetPosition = path[0];
            }
            /* Else find the closest spot on the path to the character and go to that instead. */
            else
            {
                /* Get the param for the closest position point on the path given the character's position */
                float param = path.GetParam(transform.position, rb);

                //Debug.DrawLine(transform.position, path.getPosition(param, pathLoop), Color.red, 0, false);

                if (!pathLoop)
                {
                    Vector3 finalDestination;

                    /* If we are close enough to the final destination then stop moving */
                    if (IsAtEndOfPath(path, param, out finalDestination))
                    {
                        targetPosition = finalDestination;

                        rb.Velocity = Vector3.zero;
                        return(Vector3.zero);
                    }
                }

                /* Move down the path */
                param += pathDirection * pathOffset;

                /* Set the target position */
                targetPosition = path.GetPosition(param, pathLoop);

                //Debug.DrawLine(transform.position, targetPosition, Color.red, 0, false);
            }

            return(steeringBasics.Arrive(targetPosition));
        }