/// <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()); }
/// <summary> /// Starts up the planner. /// </summary> /// <returns>True on success.</returns> public bool Enter() { // Note: Will never return false. mSpeed = Mathf.Sqrt(agent.data.desiredSpeedSq); agent.RemoveFromCrowd(); agent.SetCorridorAssets(false); agent.SetPathAssets(true); return(true); }
/// <summary> /// Starts up the planner. /// </summary> /// <returns>True on success.</returns> public bool Enter() { if (agent.navGroup.query == null) { return(false); } NavmeshPoint pos = agent.GetPointSearch(agent.data.position); if (pos.polyRef == 0) { Debug.LogError(string.Format( "{0}: Could not constrain position to navigation mesh. {1}" , agent.transform.name, pos.ToString())); return(false); } NavmeshPoint goal = agent.GetPointSearch(agent.data.goal); if (goal.polyRef == 0) { Debug.LogError(string.Format("{0}: Could not constrain goal to navigation mesh. {1}" , agent.transform.name, goal.ToString())); return(false); } agent.RemoveFromCrowd(); agent.SetCorridorAssets(true); agent.SetPathAssets(false); if (agent.PlanCorridor(pos, goal) <= 0) { Debug.LogError(string.Format("{0}: Could not plan corridor on enter." , agent.transform.name)); agent.data.flags &= ~NavFlag.CorridorInUse; return(false); } agent.data.desiredPosition = agent.corridor.Position; agent.data.plannerGoal = agent.corridor.Target; agent.data.flags &= ~(NavFlag.HasNewPosition | NavFlag.HasNewGoal); mSpeed = Mathf.Sqrt(agent.data.desiredSpeedSq); mOptimizationTimer = OptimizationFrequency; return(true); }
private void Suspend() { mPlanner.Exit(); mPlanner = NullState.Instance; agent.RemoveFromCrowd(); agent.SetCorridorAssets(false); agent.SetPathAssets(false); // Note: The desired position is purposely left alone since it may be the cause of the // problem. Don't want to wipe out that bit of information. // agent.data.desiredPosition = agent.data.position; agent.data.desiredVelocity = Vector3.zero; agent.data.desiredSpeedSq = 0; agent.data.flags &= ~NavFlag.PlannerFailed; }
/// <summary> /// Starts up the planner. /// </summary> /// <returns>True if successful.</returns> public bool Enter() { if (agent == null || agent.navGroup.query == null || agent.navGroup.crowd == null) { return(false); } NavmeshPoint pos = agent.GetPointSearch(agent.data.position); if (pos.polyRef == 0) { Debug.LogError(string.Format( "{0}: Could not constrain position to navigation mesh. {1}" , agent.transform.name, pos.ToString())); return(false); } agent.RemoveFromCrowd(); CrowdAgentParams config = agent.crowdConfig; config.maxSpeed = 0; agent.crowdAgent = agent.navGroup.crowd.AddAgent(agent.data.plannerGoal.point, config); if (agent.crowdAgent == null) { Debug.LogError(string.Format("{0}: Could not add agent to the crowd." , agent.transform.name)); return(false); } agent.data.flags &= ~NavFlag.CrowdConfigUpdated; agent.data.desiredPosition = agent.data.position; agent.data.desiredSpeedSq = 0; agent.data.desiredVelocity = Vector3.zero; agent.SetCorridorAssets(false); agent.SetPathAssets(false); return(true); }