/// <summary> /// Move the agent to their target. /// </summary> /// <param name="nextAction">The action the worker is moving towards to achieve their goal</param> /// <returns>If the agent has reached their destination.</returns> public bool MoveAgent(GOAPAction nextAction) { // If the worker is within interation range of their target, they have reached their destination. if ((transform.position - nextAction.GetTarget().transform.position).magnitude < m_InteractionRange) { nextAction.SetInRange(true); m_HaveDestination = false; m_NavAgent.destination = transform.position; return(true); } // Else, they're still going. else { // Set the nav mesh agent's destination to the destination of the goal. if (m_HaveDestination == false) { m_NavAgent.destination = nextAction.GetTarget().transform.position; m_HaveDestination = true; } return(false); } }
/// <summary> /// Create the move state. /// </summary> private void CreateMoveToState() { m_MoveToState = (fsm, gameObject) => { GOAPAction action = m_CurrentActions.Peek(); // If the current actions requires us to be in range of a target but we couldn't find a target, go to the idle state. if (action.RequiresInRange() && action.GetTarget() == null) { fsm.RemoveState(); fsm.RemoveState(); fsm.AddState(m_IdleState); return; } // If the agent has reached the target of their current action, move to the next state. if (m_DataProvider.MoveAgent(action)) { fsm.RemoveState(); } }; }