Ejemplo n.º 1
0
        IEnumerator SwithState(ArcherState archerState, float delay)
        {
            swithState = true;
            yield return(new WaitForSeconds(delay));

            _archerState = archerState;
            swithState   = false;
        }
Ejemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     horizontalForAngle = new Vector2(startPosition.x + 3f, startPosition.y);
     stats.Init();
     archerState   = ArcherState.Patrol;
     startPosition = transform.position;
     player        = FindObjectOfType <Player>();
     rb            = GetComponent <Rigidbody2D>();
 }
Ejemplo n.º 3
0
    // Use this for initialization
    public override void Start()
    {
        base.Start();
        state = ArcherState.attacking;
        characterType = CharacterConstants.CharacterType.enemy;

        //set our gnoll's abilities
        abilityOne = new MoveScript(this);
        abilityTwo = new RockThrowScript(this);
    }
Ejemplo n.º 4
0
 public override void StartTurn()
 {
     base.StartTurn();
     state = ArcherState.attacking;
     //TODO: if i'm under 25%, consider running away
     //otherwise, move to max range and try to attack.
     /*
     if(health < 6) {
         if(Random.Range(0,100) < 25) {
             state = ArcherState.running;
         }
     }
     else {
         state = ArcherState.attacking;
     }
     */
 }
Ejemplo n.º 5
0
    private void enemy_ai()
    {
        RaycastHit2D hitInfo;

        switch (archerState)
        {
        case ArcherState.Patrol:

            if (stopBetweenTurnTimer > 0)
            {
                rb.velocity           = new Vector2(0, rb.velocity.y);
                stopBetweenTurnTimer -= Time.deltaTime;
                // Debug.Log("time: " + stopBetweenTurnTimer);
            }
            else
            {
                rb.velocity = new Vector2(speed, rb.velocity.y);

                RaycastHit2D groundInfo = Physics2D.Raycast(groundCheck.position, Vector2.down, groundCheckDistance);
                if (groundInfo.collider == null)
                {
                    // Debug.Log("No ground");
                    if (stopBetweenTurnTimer < 0)
                    {
                        stopBetweenTurnTimer = 0;
                        Flip();
                    }
                    else if (stopBetweenTurnTimer == 0)
                    {
                        stopBetweenTurnTimer = stopBetweenTurnSetTimer;
                    }
                }



                if (facingRight)
                {
                    if (Mathf.Abs(transform.position.x - startPosition.x) >= patrolDistance)
                    {
                        //Debug.Log("over patrol distance (right)");
                        if (stopBetweenTurnTimer < 0)
                        {
                            stopBetweenTurnTimer = 0;
                            Flip();
                        }
                        else
                        {
                            stopBetweenTurnTimer = stopBetweenTurnSetTimer;
                        }


                        Debug.DrawLine(lineOfSightStart.position, new Vector2(lineOfSightStart.position.x + patrolFOVdistance, lineOfSightStart.position.y), Color.red);
                    }
                }
                else
                {
                    if (Mathf.Abs(startPosition.x - transform.position.x) >= patrolDistance)
                    {
                        //Debug.Log("over patrol distance (left)");
                        if (stopBetweenTurnTimer < 0)
                        {
                            stopBetweenTurnTimer = 0;
                            Flip();
                        }
                        else
                        {
                            stopBetweenTurnTimer = stopBetweenTurnSetTimer;
                        }
                    }
                    Debug.DrawLine(lineOfSightStart.position, new Vector2(lineOfSightStart.position.x - patrolFOVdistance, lineOfSightStart.position.y), Color.red);
                }

                hitInfo = (facingRight) ? Physics2D.Raycast(lineOfSightStart.position, lineOfSightStart.right, patrolFOVdistance, ~arrowLayerMask) : Physics2D.Raycast(lineOfSightStart.position, lineOfSightStart.right * -1, patrolFOVdistance, ~arrowLayerMask);
                if (hitInfo.collider != null)
                {
                    if (facingRight && (Mathf.Abs(hitInfo.point.x - lineOfSightStart.transform.position.x) < 0.5f))
                    {
                        // Debug.Log("wall (right)");
                        Debug.Log(hitInfo.transform.name);
                        if (stopBetweenTurnTimer < 0)
                        {
                            stopBetweenTurnTimer = 0;
                            Flip();
                        }
                        else
                        {
                            stopBetweenTurnTimer = stopBetweenTurnSetTimer;
                        }
                    }
                    else if (!facingRight && (Mathf.Abs(lineOfSightStart.transform.position.x - hitInfo.point.x) < 0.5f))
                    {
                        // Debug.Log("wall (left)");
                        if (stopBetweenTurnTimer < 0)
                        {
                            stopBetweenTurnTimer = 0;
                            Flip();
                        }
                        else
                        {
                            stopBetweenTurnTimer = stopBetweenTurnSetTimer;
                        }
                    }
                }

                if (isPlayerSeen())
                {
                    archerState = ArcherState.Aiming;
                    aimingTimer = aimingSetTimer;
                }
            }

            break;


        case ArcherState.Aiming:

            rb.velocity = new Vector2(0, rb.velocity.y);
            if (aimingTimer > 0)
            {
                aimingTimer -= Time.deltaTime;
                if ((facingRight && (player.transform.position.x < transform.position.x)) || (!facingRight && (player.transform.position.x > transform.position.x)))
                {
                    Flip();
                }
            }
            else
            {
                archerState = ArcherState.Attack;
                aimingTimer = aimingSetTimer;
            }
            break;

        case ArcherState.Attack:

            //Instantiate(arrow_, new Vector3(-150, 20, 0), Quaternion.Euler(new Vector3(0, 0, 0)));
            Vector3 relativePos = player.transform.position - shootingPos.position;
            //Debug.Log("WHAT "+Quaternion.LookRotation(relativePos, Vector3.up));
            Instantiate(arrow, shootingPos.position, Quaternion.Euler(new Vector3(0, 0, Mathf.Atan2(player.transform.position.y - shootingPos.position.y, player.transform.position.x - shootingPos.position.x) * 180 / Mathf.PI)));
            //Debug.Log(arrow.transform.localRotation);
            if (isPlayerSeen())
            {
                archerState = ArcherState.Aiming;
            }
            else
            {
                archerState = ArcherState.Patrol;
            }

            break;
        }
    }
Ejemplo n.º 6
0
 private void Start()
 {
     _enemyData   = GetComponent <EnemyData>();
     ray          = new Ray(transform.position, transform.forward);
     _archerState = ArcherState.idle;
 }