/// <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); }
/// <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) { // Agent in invalid state. 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); } if (agent.AddToCrowd(pos.point) == null) { Debug.LogError(string.Format("{0}: Could not add agent to the crowd." , agent.transform.name)); return(false); } agent.data.desiredPosition = pos; agent.data.plannerGoal = goal; agent.data.flags &= ~(NavFlag.HasNewPosition | NavFlag.HasNewGoal); agent.SetCorridorAssets(false); agent.SetPathAssets(true); return(HandlePositionFeedback()); }
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); }
/// <summary> /// Initialize the planner. /// </summary> /// <remarks> /// <para> /// This method will fail on any problem, including failure to constrain the input points /// to the navigation mesh and problems adding the agent to the crowd manager. /// </para> /// </remarks> /// <returns>True if the startup was a success.</returns> public bool Enter() { if (agent.navGroup.query == null) { return(false); } NavmeshPoint pos = agent.GetPointSearch(agent.data.position); NavmeshPoint goal = agent.GetPointSearch(agent.data.goal); if (pos.polyRef == 0 || goal.polyRef == 0) { Debug.LogError(string.Format( "{0}: Could not constrain point(s) to navigation mesh. Position: {1}, Goal: {2}" , agent.transform.name, pos.ToString(), goal.ToString())); return(false); } if (agent.AddToCrowd(pos.point) == null) { Debug.LogError( string.Format("{0}: Could not add agent to crowd.", agent.transform.name)); return(false); } agent.SetCorridorAssets(false); agent.SetPathAssets(false); if (!agent.crowdAgent.RequestMoveTarget(goal)) { Debug.LogError( string.Format("{0}: Request agent move failed.", agent.transform.name)); return(false); } agent.data.plannerGoal = goal; agent.data.desiredPosition = pos; // Just in case it's new. agent.data.flags &= ~(NavFlag.HasNewPosition | NavFlag.HasNewGoal); return(true); }