void FixedUpdate()
    {
        // get the distance between this enemy and the player
        float distance = Vector3.Distance(transform.position, player.transform.position);

        enemyMovement.Rotation(direction);
        enemyAnimation.Movement(direction.magnitude);

        if (distance > 15)
        {
            Rolling();
        }
        else if (distance > 2.5f)
        {
            // get the final position, that is,
            // the distance between the enemy and the player
            direction = player.transform.position - transform.position;

            // checks if enemy and player are not colliding.
            // The 2.5f is because both enemy and player have a Capsule Collider with radius equal 1,
            // so if the distance is bigger than both radius they are colliding
            enemyMovement.Movement(direction, enemyStatus.speed);

            // if they're not colliding the Attacking animation is off
            enemyAnimation.Attack(false);
        }
        else
        {
            direction = player.transform.position - transform.position;
            // otherwise, the Attacking animation is on
            enemyAnimation.Attack(true);
        }
    }
    //******************************************** Animation ************************************************

    protected virtual void ControlAnimation()
    {
        if (IsDead())
        {
            sprite.Die();
        }
        else if (flinchTime > 0)
        {
            sprite.Flinch();
        }
        else if (IsAttacking())
        {
            sprite.Attack();
        }
        else if (isJumping())
        {
            sprite.Jump();
        }
        else if (isOnGround())
        {
            if (isRunning())
            {
                sprite.Walk(rigidbody2d.velocity.x / 4f);
            }
            else
            {
                sprite.Idle();
            }
        }
        else
        {
            sprite.Glide();
        }
    }
Exemple #3
0
        public void Update()
        {
            // Actions

            if (Input.GetKeyDown(KeyCode.A))
            {
                CharacterAnimation.Attack();
            }

            // Moves

            if (Input.GetKeyDown(KeyCode.I))
            {
                CharacterAnimation.SetState(CharacterState.Idle);
            }

            if (Input.GetKeyDown(KeyCode.E))
            {
                CharacterAnimation.SetState(CharacterState.Ready);
            }

            if (Input.GetKeyDown(KeyCode.W))
            {
                CharacterAnimation.SetState(CharacterState.Walk);
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                CharacterAnimation.SetState(CharacterState.Run);
            }

            if (Input.GetKeyDown(KeyCode.J))
            {
                CharacterAnimation.SetState(CharacterState.Jump);
            }

            if (Input.GetKeyDown(KeyCode.C))
            {
                CharacterAnimation.SetState(CharacterState.Climb);
            }

            // Direction

            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                TurnLeft();
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                TurnRight();
            }
            else if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                TurnUp();
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                TurnDown();
            }
        }
Exemple #4
0
    private void Update()
    {
        agent.SetDestination(player.position);
        bossAnimation.Movement(agent.velocity.magnitude);

        if (agent.hasPath)
        {
            bool closeToPlayer = agent.remainingDistance <= agent.stoppingDistance;
            if (closeToPlayer)
            {
                bossAnimation.Attack(true);
                Vector3 direction = player.position - transform.position;
                bossMovement.Rotation(direction);
            }
            else
            {
                bossAnimation.Attack(false);
            }
        }
    }
Exemple #5
0
 void Attack()
 {
     if (!attackPlayer)
     {
         return;
     }
     currentAttackTime += Time.deltaTime;
     if (currentAttackTime > defaultAttackTime)
     {
         charAnimation.Attack(Random.Range(0, 3));
         currentAttackTime = 0f;
     }
     if (Vector3.Distance(transform.position, playerTarget.position) > attackDistance + chasePlayerAfterAttack)
     {
         attackPlayer = false;
         followPlayer = true;
     }
 }
Exemple #6
0
    //bool IsrestrictedState(GenericState currentState)
    //{
    //    if (currentState == GenericState.attack || currentState == GenericState.ability)
    //    {
    //        return true;
    //    }
    //    return false;
    //}
    //void SetState(GenericState newState)
    //{
    //    myState.ChangeState(newState);
    //}


    void GetInput()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            CharacterAnimation.Attack();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            CharacterAnimation.SetState(CharacterState.Run);
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            CharacterAnimation.SetState(CharacterState.Walk);
        }
        if (Input.GetKeyDown(KeyCode.J))
        {
            CharacterAnimation.SetState(CharacterState.Jump);
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            CharacterAnimation.SetState(CharacterState.Climb);
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            CharacterAnimation.Die();
        }

        if (Input.GetKeyDown(KeyCode.H))
        {
            CharacterAnimation.Hit();
        }

        // if (Input.GetButtonDown("Attack"))
        //{
        //    StartCoroutine(WeaponCo());
        //    tempMovement = Vector2.zero;
        //    Motion(tempMovement);
        //}
        //else if (Input.GetButtonDown("Ability") && currentAbility)
        //{

        //    StartCoroutine(AbilityCo(currentAbility.duration));
        //}
        // else
        // if (CharacterAnimation.GetState() == CharacterState.Walk)
        {
            tempMovement.x = Input.GetAxisRaw("Horizontal");

            tempMovement.y = Input.GetAxisRaw("Vertical");

            Motion(tempMovement);
        }
        //else
        //{

        //    tempMovement = Vector2.zero;
        //    Motion(tempMovement);
        //}
    }
Exemple #7
0
    void Update()
    {
        if (!GameController.instance.isGamePaused)
        {
            string dashInputName = player.GetPlayerInputPrefix() + "Dash";
            if (Input.GetAxis(dashInputName) < InputThreshold && isDashPressed)
            {
                isDashPressed = false;
            }
            else if (Input.GetAxis(dashInputName) > InputThreshold && !isDashPressed)
            {
                isDashPressed = true;
                if (dashReloadTime + dashReloadBonusFactor <= 0)
                {
                    body.AddForce(player.GetMovementDirection() * dashForce, ForceMode.VelocityChange);
                    dashReloadTime = dashReloadDuration;
                    characterAnimation.Dash();
                }
            }
            if (dashReloadTime > 0)
            {
                dashReloadTime -= Time.deltaTime;
            }

            if (player.isOnGround && Input.GetButtonDown(player.GetPlayerInputPrefix() + "Jump"))
            {
                body.AddForce(transform.up * jumpForce.y + player.GetMovementDirection() * jumpForce.x, ForceMode.VelocityChange);
                characterAnimation.Jump();
            }

            string meleeInputName = player.GetPlayerInputPrefix() + "Melee";
            if (meleeReloadTime > 0)
            {
                meleeReloadTime -= Time.deltaTime;
            }
            if (Input.GetButton(meleeInputName) && isInRangeOfTransmitter)
            {
                transmitter.arePlayersChanneling[player.playerIndex] = true;
            }
            else
            {
                transmitter.arePlayersChanneling[player.playerIndex] = false;
            }

            if (meleeReloadTime <= 0 && Input.GetButtonDown(meleeInputName))
            {
                List <HealthController> entitiesAtRange = meleeHitbox.GetEntitiesAtRange();
                for (int i = 0; i < entitiesAtRange.Count; i++)
                {
                    entitiesAtRange[i].GetComponentInChildren <Animator>().SetTrigger("Hit");
                    Vector3 direction = entitiesAtRange[i].transform.position - transform.position;
                    direction.y = 0;
                    direction   = direction.normalized;
                    entitiesAtRange[i].GetComponent <Rigidbody>().AddForce(Vector3.up * meleePushback.y + direction * meleePushback.x, ForceMode.Impulse);
                    entitiesAtRange[i].MeleeHit(meleeDamage);
                    weaponController.StealWeapon(entitiesAtRange [i].GetComponent <WeaponController> ());
                }
                meleeReloadTime = meleeReloadDuration;
                characterAnimation.Attack();
            }
        }
    }