示例#1
0
    //------------------------------------
    public IEnumerator StateAttack()
    {
        //Run attack animation
        ThisAnimator.SetInteger("AnimState", (int)ActiveState);

        //While in idle state
        while (ActiveState == AISTATE.ATTACK)
        {
            //Look at player
            Vector3 PlanarPosition = new Vector3(PlayerTransform.position.x, ThisTransform.position.y, PlayerTransform.position.z);
            ThisTransform.LookAt(PlanarPosition, ThisTransform.up);

            //Get distance between enemy and player
            float Distance = Vector3.Distance(PlayerTransform.position, ThisTransform.position);

            if (Distance > ThisAgent.stoppingDistance * 2f)
            {
                ThisAgent.Stop();
                yield return(null);

                ActiveState = AISTATE.CHASE;
                yield break;
            }

            yield return(null);
        }
    }
示例#2
0
    //------------------------------------
    public void Die()
    {
        //Update Game Score
        GameManager.ThisInstance.Score += ScorePoints;
        ScoreText.OnScoreChange.Invoke();

        //Calcluate Bonus, if achieved
        float LettersPerSecond = AssocWord.Length / Typer.ElapsedTime;

        //If we beat best times, then get bonus
        if (LettersPerSecond < Typer.RecordLettersPerSecond)
        {
            //Bonus achieved
            ++GameManager.ThisInstance.BonusLevel;
        }

        ActiveState = AISTATE.DEAD;
        --ActiveEnemies;

        //Reset matched word
        MatchedWord = string.Empty;

        //Update Navigator
        Navigator.ThisInstance.EnemyDie.Invoke();
    }
示例#3
0
    public void SwitchState(AISTATE nextState)
    {
        if (IsAlive /*&& IsGrounded*/)
        {
            switch (nextState)
            {
            case AISTATE.Wander:
                agent.enabled = false;
                break;

            case AISTATE.Seek:
                agent.enabled = true;
                agent.Resume();
                break;

            case AISTATE.Attack:
                agent.enabled = true;
                agent.Resume();
                break;

            case AISTATE.Death:
                agent.enabled = false;
                break;
            }
        }
        currAIState = nextState;
    }
示例#4
0
    //------------------------------------
    public IEnumerator StateChase()
    {
        ++ActiveEnemies;

        //Run chase animation
        ThisAnimator.SetInteger("AnimState", (int)ActiveState);

        //Set destination
        ThisAgent.SetDestination(PlayerTransform.position);

        //Wait until path is calculated
        while (!ThisAgent.hasPath)
        {
            yield return(null);
        }

        //While in idle state
        while (ActiveState == AISTATE.CHASE)
        {
            if (ThisAgent.remainingDistance <= ThisAgent.stoppingDistance)
            {
                ThisAgent.Stop();
                yield return(null);

                ActiveState = AISTATE.ATTACK;
                yield break;
            }

            yield return(null);
        }
    }
示例#5
0
 void Awake()
 {
     //if (IsGrounded)
     {
         currAIState   = AISTATE.Wander;
         EnemiesKilled = 0;
     }
 }
示例#6
0
    IEnumerator ContinuePatrol()
    {
        yield return(new WaitForSeconds(2));

        aiState = AISTATE.Patrol;
        PatrolStateAction();
        reachLastSeen = false;
        reachTarget   = false;
    }
    void Idle()
    {
        if (target == null)
        {
            target = GameManager.Instance.GetListOfActivePlayers().RandomObject().transform;
        }

        currenState = AISTATE.CHASING;
    }
示例#8
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case AISTATE.IDLE:
            if (Vector2.Distance(transform.position, player.transform.position) <= detection_range)     // Player is in detection range
            {
                state = AISTATE.DETECTED;
            }
            break;

        case AISTATE.DETECTED:
            if (Vector2.Distance(transform.position, player.transform.position) < attack_range)     // Player is in attack range
            {
                state = AISTATE.ATTACKING;
            }
            else
            {
                Vector3 translation = (player.transform.position - transform.position).normalized * searching_speed * Time.deltaTime;
                translation.y *= 0.1f;
                transform.Translate(translation);
            }
            break;

        case AISTATE.ATTACKING:
            if (aim_point == Vector3.zero)
            {
                y_start_value = transform.position.y;
                aim_point     = player.transform.position + (player.transform.position - transform.position).normalized;
            }
            else
            {
                if ((transform.position - aim_point).magnitude > epsilon)
                {
                    transform.position = Vector3.MoveTowards(transform.position, aim_point, attacking_speed * Time.deltaTime);
                }
                else
                {
                    state     = AISTATE.ATTACKED;
                    aim_point = Vector3.zero;
                }
            }
            break;

        case AISTATE.ATTACKED:
            if (transform.position.y <= y_start_value)
            {
                transform.Translate(Vector3.up * searching_speed * Time.deltaTime);
            }
            else
            {
                state = AISTATE.IDLE;
            }
            break;
        }
    }
示例#9
0
    //------------------------------------
    void Start()
    {
        //Set active state
        ActiveState = mActiveState;

        //Get random word
        AssocWord = WordList.ThisInstance.GetRandomWord();

        UpdateText();
    }
示例#10
0
 public void Heal(int heal)
 {
     _needHeal = false;
     _canBlock = true;
     _saberControl.Heal(heal);
     runSpeed         *= 1.5f;
     agent.speed       = runSpeed;
     agent.autoBraking = false;
     cAIState          = AISTATE.pursue;
 }
示例#11
0
 /// <summary>
 /// aiStateの変更
 /// </summary>
 /// <param name="state"></param>
 /// <param name="t"></param>
 protected void SetAIState(AISTATE state, float t)
 {
     aiStartTime  = Time.fixedTime;
     aiWaitLength = t;
     aiState      = state;
     if (state == AISTATE.AISELECT)
     {
         AISelectDisturb();
     }
 }
示例#12
0
    public void PlayerKnockOutCheck()
    {
        if (target != null)
        {
            if (!GameManager.Instance.GetListOfActivePlayers().Contains(target.gameObject.GetComponent <Entity>()))
            {
                target      = null;
                currenState = AISTATE.IDLE;
            }
        }

        currenState = AISTATE.IDLE;
    }
示例#13
0
    void Chase()
    {
        int layer = LayerMask.NameToLayer("GunColliderLayer");

        layer = ~layer;

        RaycastHit2D hit = Physics2D.Raycast(transform.position + (target.position - transform.position).normalized, target.position - transform.position, layer);

        if (checkEngageRange(hit.collider.transform))
        {
            currenState = AISTATE.ATTACK;
        }
    }
示例#14
0
    //-----------------------------------
    public void ChangeState(AISTATE NewState)
    {
        StopAllCoroutines();
        CurrentState = NewState;

        switch (NewState)
        {
        case AISTATE.IDLE:
            StartCoroutine(Idle());
            break;

        case AISTATE.ATTACK:
            StartCoroutine(Attack());
            break;
        }
    }
示例#15
0
    private void Attack()
    {
        int layer = LayerMask.NameToLayer("GunColliderLayer");

        layer = ~layer;
        RaycastHit2D hit = Physics2D.Raycast(transform.position + (target.position - transform.position).normalized, target.position - transform.position, layer);

        if (checkEngageRange(hit.collider.transform))
        {
            Aim();
            Fire();
        }
        else
        {
            currenState = AISTATE.CHASING;
        }
    }
示例#16
0
    public IEnumerator StateChase()
    {
        WeaponPS.Stop();
        ThisAgent.SetDestination(ThisPlayer.position);

        while (CurrentState == AISTATE.CHASE)
        {
            //Check distance
            float DistancetoDest = Vector3.Distance(ThisTransform.position, ThisPlayer.position);

            if (Mathf.Approximately(DistancetoDest, ThisAgent.stoppingDistance) || DistancetoDest <= ThisAgent.stoppingDistance)
            {
                CurrentState = AISTATE.ATTACK;
                yield break;
            }

            yield return(null);
        }
    }
示例#17
0
    Kill()
    {
        if (deaths < lives)
        {
            deaths++;

            agent.speed       = retreatMultiplier * runSpeed;
            agent.autoBraking = true;
            agent.destination = batLocNear.position;
            _needHeal         = true;
            _canBlock         = false;

            cAIState = AISTATE.retreat;
        }
        else if (deaths == lives)
        {
            Debug.Log("Vader has been Killed!");
            Victory._deadVader = true;
            Destroy(this.gameObject, 0.0f);
        }
    }
示例#18
0
 //------------------------------------
 public void WakeUp()
 {
     ActiveState = AISTATE.CHASE;
 }
示例#19
0
    // Update is called once per frame
    void Update()
    {
        switch (cAIState)
        {
        case AISTATE.patrol:
            //action
            if (!agent.pathPending && agent.remainingDistance < 0.5f)
            {
                NextPoint();
            }

            //update
            if (_needHeal)
            {
                cAIState = AISTATE.retreat;
            }

            if (alertedToPlayer)
            {
                cAIState          = AISTATE.pursue;
                agent.destination = playerTransf.position;
            }
            if (firedAt)
            {
                cAIState = AISTATE.block;
            }
            break;

        case AISTATE.pursue:
            //action
            if (playerTransf != null && !_needHeal)
            {
                agent.destination = playerTransf.position;
            }
            else
            {
                cAIState = AISTATE.patrol;
                NextPoint();
            }

            //update
            if (agent.remainingDistance < 1.0f)
            {
                cAIState = AISTATE.attack;
            }
            if (firedAt)
            {
                cAIState = AISTATE.block;
            }
            break;

        case AISTATE.block:
            //action
            if (bulletTransf != null && Vector3.Distance(transform.position, bulletTransf.position) < 4 && _canBlock)
            {
                Block(bulletTransf, 10);
                firedAt = false;
            }
            //update
            if (_needHeal)
            {
                _canBlock         = false;
                agent.speed       = retreatMultiplier * runSpeed;
                agent.destination = batLocNear.position;
                cAIState          = AISTATE.retreat;
            }
            else if (!firedAt && playerTransf != null)
            {
                cAIState = AISTATE.pursue;
            }
            else if (!firedAt)
            {
                if (Physics.Raycast(new Ray(transform.position, _player.transform.position - transform.position), out outHit))
                {
                    if (outHit.collider.tag == "Player")
                    {
                        if (Vector3.Dot(transform.forward, _player.transform.position - transform.position) > 0)
                        {
                            cAIState     = AISTATE.pursue;
                            playerTransf = _player.transform;
                        }
                        else
                        {
                            cAIState = AISTATE.patrol;
                        }
                    }
                    else
                    {
                        cAIState = AISTATE.patrol;
                    }
                }
                else
                {
                    cAIState = AISTATE.patrol;
                }
            }
            break;

        case AISTATE.retreat:
            //action
            //update
            break;

        case AISTATE.attack:
            //action
            IDamageable player = playerTransf.GetComponentInParent <IDamageable> ();
            player.Damage(102);
            //update
            break;
        }
    }
示例#20
0
 //update ai state according to the situation
 public void Update()
 {
     //change to engage state once target inside ai unit vision
     if ((visionScript.visibleTargets.Count > 0 && aiState != AISTATE.Engage) || (hearingScript.visibleTargets.Count > 0 && aiState != AISTATE.Engage))
     {
         aiState = AISTATE.Engage;
         if (visionScript.visibleTargets.Count > 0)
         {
             EngageStateAction(visionScript.visibleTargets[0]);
         }
         else if (hearingScript.visibleTargets.Count > 0)
         {
             EngageStateAction(hearingScript.visibleTargets[0]);
         }
     }
     else if (aiState == AISTATE.Engage && visionScript.visibleTargets.Count <= 0 && hearingScript.visibleTargets.Count <= 0 && predictionTrigger)
     {
         aiState     = AISTATE.Predict;
         unit.target = null;
         PredictionStateAction();
     }
     // change state from engage to search once the ai unit lost their target
     else if (aiState == AISTATE.Engage && visionScript.visibleTargets.Count <= 0 && hearingScript.visibleTargets.Count <= 0 && !predictionTrigger)
     {
         aiState     = AISTATE.Search;
         unit.target = null;
         SearchStateAction();
     }
     //patrol around the game environment
     else if (aiState == AISTATE.Patrol)
     {
         if (Vector3.Distance(this.transform.position, target.targetTransform.position) < unit.distance && !reachTarget)
         {
             reachTarget = true;
             StartCoroutine("WaitWhileReachTarget");
         }
     }
     //search the target location where the ai unit last seen the target
     else if (aiState == AISTATE.Search)
     {
         if (Vector3.Distance(this.transform.position, unit.target.position) < unit.distance && !reachLastSeen)
         {
             Debug.Log("inside search state");
             reachLastSeen = true;
             StopCoroutine("ContinuePatrol");
             StartCoroutine("ContinuePatrol");
         }
     }
     //engage once the ai unit found their target and get near to it
     else if (aiState == AISTATE.Engage)
     {
         Debug.Log("in engage");
         if (Vector3.Distance(this.transform.position, unit.target.position) < unit.distance && !isAttacking && !isReloading)
         {
             Debug.Log("in attack range");
             StartCoroutine("Attack");
         }
     }
     else if (aiState == AISTATE.Predict)
     {
         Debug.Log("inside Predict state");
         if (Vector3.Distance(this.transform.position, unit.target.position) < unit.distance && !reachLastSeen)
         {
             Debug.Log("inside Predict state");
             reachLastSeen = true;
             StopCoroutine("ContinuePatrol");
             StartCoroutine("ContinuePatrol");
         }
     }
 }
示例#21
0
 private void Start()
 {
     CurrentState = _CurrentState;
 }
示例#22
0
 // Start is called before the first frame update
 void Start()
 {
     state         = AISTATE.IDLE;
     y_start_value = transform.position.y;
     aim_point     = Vector3.zero;
 }
示例#23
0
 private void OnEnable()
 {
     CurrentState = AISTATE.CHASE;
 }