示例#1
0
        public bool MoveAgent(GOAPAction nextAction)
        {
            //destination
            //has the destination been reached
            if (!NodeManager.instance._initialized)
            {
                UnityEngine.Debug.LogWarning("Has not initialized yet");

                return(false);
            }

            destination = nextAction.target.transform.position;

            AssignPath();

            // Don't touch this.
            if (Vector3.Distance(gameObject.transform.position, nextAction.target.transform.position) <= 3.5f)
            {
                // we are at the target location, we are done
                nextAction.SetInRange(true);
                needPath      = true;
                index         = 0;
                atDestination = true;
                return(true);
            }
            else
            {
                StepAgent();

                return(false);
            }
        }
示例#2
0
    /// <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);
        }
    }