Example #1
0
    public override BT_NodeStates Evaluate()
    {
        m_dt += Time.fixedDeltaTime;

        m_AI.GetAgentNavMesh().speed = 0f;
        if (m_AI.GetState() != State.IDLE)
        {
            if (m_AI.GetAnim() != null)
            {
                m_AI.GetAnim().Play("IDLE");
            }
            m_AI.SetState(State.IDLE);
        }

        if (m_AI.GetIsSuspicious())
        {
            return(BT_NodeStates.SUCESS);
        }
        else
        {
            if (m_waitingTime < m_dt)
            {
                m_dt          = 0;
                m_waitingTime = Random.Range(0, 3);
                return(BT_NodeStates.SUCESS);
            }
            else
            {
                return(BT_NodeStates.FAILURE);
            }
        }
    }
Example #2
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);
    }
Example #3
0
    public override BT_NodeStates Evaluate()
    {
        Vector3 agentPos  = m_AI.GetAgentTransform().position;
        Vector3 targetPos = m_AI.GetTargetPos();
        float   dist      = Vector3.Distance(agentPos, targetPos);

        if (dist < m_range)
        {
            if (m_AI.GetState() != State.IDLE)
            {
                if (m_AI.GetAnim() != null)
                {
                    m_AI.GetAnim().Play("IDLE");
                }
                m_AI.SetState(State.IDLE);
            }
            if (m_AI.GetIsSuspicious() && !m_AI.GetIsTargetInSight())
            {
                float radius = 4f;

                //Get vector around 6 ways of target poisition
                //45,90,135,180... every 45deg
                //(transform.position.x + rcostheta,0,transform.position.z + rsintheta)
                for (int i = 0; i < 360; i += 45)
                {
                    Vector3 target = new Vector3(m_AI.GetTargetPos().x + radius * Mathf.Cos(i),
                                                 m_AI.GetAgentTransform().position.y,
                                                 m_AI.GetTargetPos().z + radius * Mathf.Sin(i));

                    Vector3    dirToTarget  = (target - agentPos).normalized;
                    float      distToTarget = Vector3.Distance(agentPos, target);
                    NavMeshHit navHit;
                    NavMesh.SamplePosition(target, out navHit, distToTarget, NavMesh.AllAreas);
                    if (Mathf.Abs(navHit.position.y - target.y) < 2f)
                    {
                        m_AI.GetWaypointList().Add(navHit.position);
                    }
                }
            }

            return(BT_NodeStates.SUCESS);
        }
        else
        {
            return(BT_NodeStates.FAILURE);
        }
    }
Example #4
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);
            }
        }
    }