예제 #1
0
    public override BT_NodeStates Evaluate()
    {
        Vector3    targetPos;
        NavMeshHit navHit;

        if (m_AI.GetWaypointList().Count() != 0)
        {
            do
            {
                int randomIndex = Random.Range(0, m_AI.GetWaypointList().Count() - 1);
                //Random for now
                targetPos = m_AI.GetWaypointList().ElementAt(randomIndex);
                m_AI.GetAgentNavMesh().speed = 2.5f;

                m_AI.SetSearchCount(m_AI.GetSearchCount() + 1);

                NavMesh.SamplePosition(targetPos, out navHit, m_range, NavMesh.AllAreas);
            } while (navHit.position.x == Mathf.Infinity);
        }
        else
        {
            do
            {
                Vector3 randomDirection = new Vector3(Random.Range(-m_range, m_range), Random.Range(-m_range, m_range), Random.Range(-m_range, m_range));
                Vector3 agentPos        = m_AI.GetAgentTransform().position;
                targetPos = randomDirection + agentPos;
                m_AI.GetAgentNavMesh().speed = 1.5f;

                NavMesh.SamplePosition(targetPos, out navHit, m_range, NavMesh.AllAreas);
            } while (navHit.position.x == Mathf.Infinity);
        }

        if (m_AI.GetSearchCount() == 5)
        {
            m_AI.IsSuspicious(false);
            m_AI.GetWaypointList().Clear();
            m_AI.SetSearchCount(0);
        }


        // Debug.Log(navHit.position);


        m_AI.SetTargetPos(navHit.position);
        if (m_AI.GetState() != State.WALK)
        {
            if (m_AI.GetAnim() != null)
            {
                m_AI.GetAnim().Play("WALK");
            }
            m_AI.SetState(State.WALK);
        }
        return(BT_NodeStates.SUCESS);
    }
예제 #2
0
    public override BT_NodeStates Evaluate()
    {
        m_enemyInSight = m_AI.EnemyInSight();
        if (m_enemyInSight.Count != 0)
        {
            foreach (Transform VisibleTargets in m_enemyInSight)
            {
                if (VisibleTargets.tag == "Player")
                {
                    m_target          = VisibleTargets;
                    mIsPlayerDetected = true;
                }
                else if (!mIsPlayerDetected)
                {
                    m_target = VisibleTargets.root;
                }
            }
            if (!mIsPlayerDetected)
            {
                float distToPlayer = Vector3.Distance(m_AI.GetAgentTransform().position, MoveSoundUI.instance.PlayerInfo.position);
                if (MoveSoundUI.instance != null)
                {
                    switch (MoveSoundUI.instance.MovementStatus)
                    {
                    case MoveSoundUI.MovementSoundStatus.High:
                        m_target = MoveSoundUI.instance.PlayerInfo;
                        break;

                    case MoveSoundUI.MovementSoundStatus.Middle:
                        if (distToPlayer < MidDist)
                        {
                            m_target = MoveSoundUI.instance.PlayerInfo;
                        }
                        break;

                    case MoveSoundUI.MovementSoundStatus.Little:
                        if (distToPlayer < LowDist)
                        {
                            m_target = MoveSoundUI.instance.PlayerInfo;
                        }
                        break;
                    }
                }
            }
            mIsPlayerDetected = false;


            NavMeshHit navHit;
            float      distToTarget = Vector3.Distance(m_AI.GetAgentTransform().position, m_target.position);
            NavMesh.SamplePosition(m_target.position, out navHit, distToTarget, NavMesh.AllAreas);
            if (Mathf.Abs(navHit.position.y - m_target.position.y) > 2f)
            {
                m_AI.IsTargetInsight(false);
                m_AI.IsSuspicious(true);
                return(BT_NodeStates.FAILURE);
            }

            m_AI.GetAgentNavMesh().speed = 4f;
            m_AI.SetTargetPos(navHit.position);

            m_AI.SetTarget(m_target);
            m_AI.GetWaypointList().Clear();
            m_AI.IsTargetInsight(true);
            m_AI.IsSuspicious(true);

            if (m_AI.GetState() != State.RUN)
            {
                if (m_AI.GetAnim() != null)
                {
                    m_AI.GetAnim().Play("RUN");
                }
                m_AI.SetState(State.RUN);
            }
            return(BT_NodeStates.SUCESS);
        }
        else
        {
            m_target = null;
            float distToPlayer = Vector3.Distance(m_AI.GetAgentTransform().position, MoveSoundUI.instance.PlayerInfo.position);
            switch (MoveSoundUI.instance.MovementStatus)
            {
            case MoveSoundUI.MovementSoundStatus.High:
                m_target = MoveSoundUI.instance.PlayerInfo;
                break;

            case MoveSoundUI.MovementSoundStatus.Middle:
                if (distToPlayer < MidDist)
                {
                    m_target = MoveSoundUI.instance.PlayerInfo;
                }
                break;

            case MoveSoundUI.MovementSoundStatus.Little:
                if (distToPlayer < LowDist)
                {
                    m_target = MoveSoundUI.instance.PlayerInfo;
                }
                break;
            }
            if (m_target != null)
            {
                NavMeshHit navHit;
                float      distToTarget = Vector3.Distance(m_AI.GetAgentTransform().position, m_target.position);
                NavMesh.SamplePosition(m_target.position, out navHit, distToTarget, NavMesh.AllAreas);

                if (Mathf.Abs(navHit.position.y - m_target.position.y) > 2f)
                {
                    m_AI.IsTargetInsight(false);
                    m_AI.IsSuspicious(true);
                    return(BT_NodeStates.FAILURE);
                }

                m_AI.GetAgentNavMesh().speed = 4f;
                m_AI.SetTargetPos(navHit.position);

                m_AI.SetTarget(m_target);
                m_AI.GetWaypointList().Clear();
                m_AI.IsTargetInsight(true);
                m_AI.IsSuspicious(true);

                if (m_AI.GetState() != State.RUN)
                {
                    m_AI.GetAnim().Play("RUN");
                    m_AI.SetState(State.RUN);
                }
                return(BT_NodeStates.SUCESS);
            }
            else
            {
                m_AI.IsTargetInsight(false);
                return(BT_NodeStates.FAILURE);
            }
        }
    }