Example #1
0
    private void UpdateAnimation()
    {
        const float FULL_CIRCLE = 360.0f;

        float angle = Mathf.Atan2(flightPoints[currPointIndex].GetFlyDirection().y, flightPoints[currPointIndex].GetFlyDirection().x) * Mathf.Rad2Deg;

        if (angle < 0.0f)
        {
            angle += FULL_CIRCLE;
        }

        if (angle <= 45.0f || angle > 315.0f)
        {
            animator.AnimationChange(BatState.FLY, BatDirection.RIGHT);
        }
        else if (angle > 45.0f && angle <= 135.0f)
        {
            animator.AnimationChange(BatState.FLY, BatDirection.BACK);
        }
        else if (angle > 135.0f && angle <= 225.0f)
        {
            animator.AnimationChange(BatState.FLY, BatDirection.LEFT);
        }
        else
        {
            animator.AnimationChange(BatState.FLY, BatDirection.FRONT);
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (!active)
        {
            return;
        }
        //Walk
        if (Vector2.Distance(playerTarget.position, this.transform.position) > 6 && waitTimer <= 0)
        {
            /*if (Vector2.Distance(playerTarget.position, this.transform.position) > 12)
             * {
             *  //Lunge
             * }
             * else*/
            if (attacking)
            {
                return;
            }
            {
                //Start Walking
                if (Mathf.Abs(playerTarget.position.x - this.transform.position.x) > Mathf.Abs(playerTarget.position.y - this.transform.position.y))
                {
                    //Walk Side
                    if (playerTarget.position.x > transform.position.x)
                    {
                        //Go right
                        animator.AnimationChange(BatState.WALK, BatDirection.RIGHT);
                        rigidbody.velocity = new Vector2(walkSpeed, 0);
                    }
                    else
                    {
                        //Go Life
                        animator.AnimationChange(BatState.WALK, BatDirection.LEFT);
                        rigidbody.velocity = new Vector2(-walkSpeed, 0);
                    }
                }
                else
                {
                    //Walk Up/Down
                    //Walk Side
                    if (playerTarget.position.y > transform.position.y)
                    {
                        //Go up
                        animator.AnimationChange(BatState.WALK, BatDirection.BACK);
                        rigidbody.velocity = new Vector2(0, walkSpeed);
                    }
                    else
                    {
                        animator.AnimationChange(BatState.WALK, BatDirection.FRONT);
                        rigidbody.velocity = new Vector2(0, -walkSpeed);
                        //Go down
                    }
                }
            }
        }
        else
        {
            if (attacking)
            {
                return;
            }
            //Attack/Idle
            rigidbody.velocity = Vector2.zero;
            attackTimer       += Time.deltaTime;
            if (attackTimer >= attackTime)
            {
                attackTimer = 0;
                waitTime    = 0;
                chooseAttack();
            }
            else
            {
                animator.AnimationChange(BatState.IDLE, animator.BatDirection);

                Debug.Log("Bat Boss is Waiting to attack");
            }
            if (waitTimer >= waitTime)
            {
                waitTimer = 0;
            }
            else
            {
                waitTimer += Time.deltaTime;
            }
        }
    }