コード例 #1
0
    public IEnumerator EnemyChase()
    {
        print("Chasing");
        while (currentState == ENEMY_STATES.chase)
        {
            checkMyVision.senstivity = checkmyvision.ensenstivity.LOW;
            // agent.acceleration = 600;

            agent.isStopped = false;
            bool destSet = agent.SetDestination(checkMyVision.lastKnownLocation);
            // print("Dest Set: " + destSet);
            while (agent.pathPending && agent.path.status == NavMeshPathStatus.PathInvalid)
            {
                print("Path Invalid: " + (agent.path.status == NavMeshPathStatus.PathInvalid));
                yield return(null);
            }
            // print("Agent Remaining Distance: " + agent.remainingDistance);
            //  print("Agent Stopping Distance: " + agent.stoppingDistance);
            if (agent.remainingDistance <= agent.stoppingDistance)
            {
                agent.isStopped = true;
                print("Sqwitching to Attack!!!!!");
                CurrentState = ENEMY_STATES.attack;

                yield break;
            }
            yield return(null);
        }
    }
コード例 #2
0
ファイル: AI_FSM.cs プロジェクト: ihteshamm123/AnimalHunt3D
    public IEnumerator EnemyAttack()
    {
        print("Attacking enemy");

        while (currentState == ENEMY_STATES.attack)
        {
            agent.isStopped = false;
            agent.SetDestination(playerTransform.position);
            while (agent.pathPending)
            {
                yield return(null);
            }
            if (agent.remainingDistance > agent.stoppingDistance)
            {
                print("Distance increased");
                CurrentState = ENEMY_STATES.patrol;
                yield break;
            }
            else
            {
                // Do something

                playerHealth.HealthPoints -= maxDamage;

                CurrentState = ENEMY_STATES.patrol;

                if (playerHealth.HealthPoints == 0)
                {
                    yield break;
                }
                print("loop ending");
            }
        }
        yield return(null);
    }
コード例 #3
0
ファイル: AI_FSM.cs プロジェクト: ihteshamm123/AnimalHunt3D
    // Start is called before the first frame update
    void Start()
    {
        GameObject[] destinations = GameObject.FindGameObjectsWithTag("Dest");
        int          pathIndex    = Random.Range(0, destinations.Length);

        patrolDestination = destinations[Random.Range(0, destinations.Length)].GetComponent <Transform>();
        //  print($"Path: {pathIndex}");
        CurrentState = ENEMY_STATES.patrol;
    }
コード例 #4
0
    // Start is called before the first frame update
    void Start()
    {
        anim = GetComponent <Animator>();
        GameObject[] destinations = GameObject.FindGameObjectsWithTag("Dest");
        int          pathIndex    = Random.Range(0, destinations.Length);

        patrolDestination = destinations[Random.Range(0, destinations.Length)].GetComponent <Transform>();
        //  print($"Path: {pathIndex}");
        agent.stoppingDistance = 3;
        CurrentState           = ENEMY_STATES.patrol;
    }
コード例 #5
0
    /// <summary>
    /// Patrol behaviour
    /// </summary>
    void Patrol()
    {
        // Firstly we check if we need to change the state
        if (m_energy <= m_energyToGetAngry)
        {
            Debug.Log("Change to angry");
            m_enemyStates = ENEMY_STATES.ANGRY;
        }
        else if (m_energy <= m_energyToFlee)
        {
            Debug.Log("Change to flee");
            m_enemyStates = ENEMY_STATES.FLEE;
        }

        // We set the animation for patrol
        if (!m_animator.GetCurrentAnimatorStateInfo(0).IsName("Patrol"))
        {
            m_animator.SetTrigger("Patrol");
        }
    }
コード例 #6
0
    public IEnumerator EnemyPatrol()
    {
        print("Patroling");
        while (currentState == ENEMY_STATES.patrol)
        {
            checkMyVision.senstivity = checkmyvision.ensenstivity.HIGH;
            agent.isStopped          = false;
            agent.SetDestination(patrolDestination.position);
            while (agent.pathPending)
            {
                yield return(null);
            }
            if (checkMyVision.targetInSight)
            {
                agent.isStopped = true;
                CurrentState    = ENEMY_STATES.chase;
                yield break;
            }

            yield return(null);
        }
    }
コード例 #7
0
    /// <summary>
    /// Flee behaviour
    /// </summary>
    void Flee()
    {
        if (m_energy > m_energyToGetAngry)
        {
            Debug.Log("Change to angry");
            m_enemyStates = ENEMY_STATES.PATROL;
        }
        else if (m_energy > m_energyToFlee)
        {
            Debug.Log("Change to flee");
            m_enemyStates = ENEMY_STATES.ANGRY;
        }

        // We set the animation for Angry
        if (!m_animator.GetCurrentAnimatorStateInfo(0).IsName("Flee"))
        {
            m_animator.SetTrigger("Flee");
        }

        // Enemy gain health in this
        m_energy += 1;
    }
コード例 #8
0
    public IEnumerator EnemyAttack()
    {
        print("Attacking enemy");
        while (currentState == ENEMY_STATES.attack)
        {
            agent.isStopped = false;
            agent.SetDestination(playerTransform.position);
            while (agent.pathPending)
            {
                yield return(null);
            }
            if (agent.remainingDistance > agent.stoppingDistance)
            {
                print("Distance zayada ho gya");
                if (anim.GetBool("stop") == true)
                {
                    anim.SetBool("stop", false);
                }
                CurrentState = ENEMY_STATES.patrol;
                yield break;
            }
            else
            {
                // Do something
                anim.SetBool("stop", true);
                playerHealth.HealthPoints -= maxDamage;
                if (playerHealth.HealthPoints == 0)
                {
                    yield break;
                }
                print("loop ending");
            }
            yield return(new WaitForSeconds(1));
        }

        yield return(null);
    }
コード例 #9
0
ファイル: AI_FSM.cs プロジェクト: ihteshamm123/AnimalHunt3D
    public IEnumerator EnemyChase()
    {
        print("Chasing");

        while (currentState == ENEMY_STATES.chase)
        {
            checkMyVision.sensitivity = CheckMyVision.Sensitivity.LOW;
            // agent.acceleration = 600;

            agent.isStopped = false;
            bool destSet = agent.SetDestination(checkMyVision.lastKnownSighting);
            // print("Dest Set: " + destSet);
            while (agent.pathPending && agent.path.status == NavMeshPathStatus.PathInvalid)
            {
                print("Path Invalid: " + (agent.path.status == NavMeshPathStatus.PathInvalid));
                yield return(null);
            }
            // print("Agent Remaining Distance: " + agent.remainingDistance);
            //  print("Agent Stopping Distance: " + agent.stoppingDistance);
            if (agent.remainingDistance <= agent.stoppingDistance)
            {
                agent.isStopped = true;
                if (!checkMyVision.targetInSight)
                {
                    CurrentState = ENEMY_STATES.patrol;
                }
                else
                {
                    print("Attacking");
                    CurrentState = ENEMY_STATES.attack;
                }
                yield break;
            }
            yield return(null);
        }
    }
コード例 #10
0
    /// <summary>
    /// Angry behaviour
    /// </summary>
    void Angry()
    {
        if (m_energy > m_energyToGetAngry)
        {
            Debug.Log("Change to angry");
            m_enemyStates = ENEMY_STATES.PATROL;
        }
        else if (m_energy <= m_energyToFlee)
        {
            Debug.Log("Change to flee");
            m_enemyStates = ENEMY_STATES.FLEE;
        }

        // We set the animation for Angry
        if (!m_animator.GetCurrentAnimatorStateInfo(0).IsName("Angry"))
        {
            m_animator.SetTrigger("Angry");
        }

        // Left because it's rotated
        Debug.DrawRay(transform.position, Vector3.left * 100f, Color.cyan);

        RaycastHit hit;

        if (Physics.Raycast(transform.position, Vector3.left, out hit, 100.0f))
        {
            // if we can shoot to the player, we do so
            if (hit.transform.gameObject.tag == "Player")
            {
                Fire();
            }
        }

        // Enemy gain health in this
        m_energy += 1;
    }