Esempio n. 1
0
        /// <summary>
        /// Handles planning when position feedback is required. (Replaces normal planning.)
        /// </summary>
        /// <returns>False on a critical failure.</returns>
        private bool HandlePositionFeedback()
        {
            // Important: Should only call this method once the desired position and planner goal
            // have been successfully constrained to the navigation mesh.

            // Make sure the path is still valid. Replan if needed.
            if (agent.PlanPath(agent.data.desiredPosition, agent.data.plannerGoal) <= 0)
            {
                // A critical failure.
                Debug.LogError(string.Format(
                                   "{0}: Path planning failed on position feedback. Position: {1}, Goal: {2}"
                                   , agent.transform.name
                                   , agent.data.desiredPosition.ToString()
                                   , agent.data.plannerGoal.ToString()));

                return(false);
            }

            agent.RemoveFromCrowd();
            agent.AddToCrowd(agent.data.desiredPosition.point);

            // Next assignment will usually force crowd target replanning.
            mTarget = agent.data.desiredPosition;

            // Since the path is known to be good, setting the local
            // target should never fail.
            return(SetLocalTarget());
        }