Beispiel #1
0
    /*
     * Function: Enemy Pathing
     * Description: Pathing for NPC
     * Author: Kevin Ho
     */
    public void pathing()
    {
        //Debug.Log(u);		//Use this debug to check pathing speed
        //Currently moving through path
        if ((u += Time.deltaTime * speed) < (ctl.Length))
        {
            targetPosition = catmull.Evaluate(u);
        }
        //Reached destination. Reset to loop
        else
        {
            u -= ctl.Length;
        }

        if (!inRange())
        {
            FaceTarget(targetPosition);                                 //Look at target points

            agent.SetDestination(targetPosition);                       //Move through path
        }

        //If in range and not a horse
        else
        {
            if (this.tag != "Horse")
            {
                state = AIC_State.INRANGE;
            }
        }
    }
Beispiel #2
0
    /*
     * Function: inWaveRange
     * Description: Check if player is within wave range of villager
     */
    /*Author: Kevin Ho*/
    public void inWaveRange()
    {
        //Save previous position
        if (!isStopped)
        {
            previousU = u;
        }

        //Player in range
        if (inRange())
        {
            isStopped = true;
            //Debug.Log("Wave range!");
            //Play wave animation
            if (OnWave != null)
            {
                agent.isStopped = true;
                FaceTarget(player.transform.position);
                //Debug.Log("Waving!");
                if (Time.time > nextWave)
                {
                    OnWave();
                    //Play Wave SFX
                    if (Time.time > nextWaveCall)
                    {
                        GetComponent <VillagerSFX>().playWaveSFX();
                        nextWaveCall = Time.time + waveCallRate;
                    }
                    nextWave = Time.time + waveRate;
                }
            }
        }
        //Out of wave range. Return back to pathing
        else
        {
            Debug.Log("Out of wave range");
            u               = previousU;
            isStopped       = false;
            agent.isStopped = false;
            state           = AIC_State.PATHING;
        }
    }
Beispiel #3
0
    void Update()
    {
        /*
         * State machine of the AI NPCs. Will handle start, pathing, player tracking when in range, and playing SFX states (Not using currently) of the AI
         * Waiting is not empty for future use
         * Creator: Kevin Ho
         */
        switch (state)
        {
        //Starting state. Moves straight to pathing
        case AIC_State.START:
            //Debug.Log("State: START");
            state = AIC_State.PATHING;
            break;

        //Pathing state of NPC
        case AIC_State.PATHING:
            //Debug.Log("State: PATHING");
            //If enemy, check if dead or in range of player. Otherwise path
            if (isEnemy && (this.tag == "Enemy"))
            {
                if (enemy.getIsDead())
                {
                    state = AIC_State.DEAD;
                    return;
                }
                else if (DistFromPlayer() <= enemyController.range)
                {
                    state = AIC_State.INRANGE;
                    return;
                }
            }
            //If enemyArcher, check if dead or in range of player. Otherwise path
            else if (isEnemy && (this.tag == "EnemyArcher"))
            {
                if (enemyArcher.getIsDead())
                {
                    state = AIC_State.DEAD;
                    return;
                }
                else if (DistFromPlayer() <= enemyArcherController.range)
                {
                    state = AIC_State.INRANGE;
                    return;
                }
                //Still pathing. Change stopping distance for pathing nodes
                else
                {
                    agent.stoppingDistance = 1.0f;
                }
            }
            //If NPC is a horse, play SFX
            else if (this.name == "Horse")
            {
                if (inSFXRange())
                {
                    GetComponent <HorseSFX>().playSFX();
                }
            }
            //If NPC is a villager, play SFX
            else if (this.tag == "Villager")
            {
                if (inSFXRange())
                {
                    GetComponent <VillagerSFX>().playSFX();
                }
            }
            pathing();
            break;

        //NPC is in range of player
        case AIC_State.INRANGE:
            //Debug.Log("State: INRANGE");
            //If is an enemy, check if dead or still in range
            if (isEnemy)
            {
                if (this.tag == "Enemy")
                {
                    if (enemy.getIsDead())
                    {
                        state = AIC_State.DEAD;
                        return;
                    }
                    else if (DistFromPlayer() > enemyController.range)
                    {
                        state = AIC_State.PATHING;
                        return;
                    }
                    else
                    {
                        if (!Player.instance.isDead)
                        {
                            enemyController.inRange();
                        }
                    }
                }
                else if (this.tag == "EnemyArcher")
                {
                    if (enemyArcher.getIsDead())
                    {
                        state = AIC_State.DEAD;
                        return;
                    }
                    else if (DistFromPlayer() > enemyArcherController.range)
                    {
                        state = AIC_State.PATHING;
                        return;
                    }
                    else
                    {
                        enemyArcherController.inRange();
                    }
                }
            }
            //Else, normal NPC, check if in wave range
            else
            {
                inWaveRange();
            }
            break;

        //Play SFX (For any future implementations)
        case AIC_State.SFX:
            //Debug.Log("State: SFX");
            //if (this.name == "Horse") {
            //GetComponent<HorseSFX>().playSFX();
            //}
            state = AIC_State.PATHING;
            break;

        //NPC is dead. Waiting state
        case AIC_State.DEAD:
            //Debug.Log("State: DEAD");
            break;
        }
    }