Exemple #1
0
    public void PlayDodgeAnimation(Vector3 dir)
    {
        EnableNormalSkeleton();
        playerPunch.enabled = false;
        playerSword.enabled = false;

        playerBase.PlayDodgeAnimation(dir);
    }
Exemple #2
0
    private void Update()
    {
        switch (state)
        {
        case State.Normal:
            chargeDelay -= Time.deltaTime;
            enemyTarget  = enemyMain.EnemyTargeting.GetActiveTarget();
            if (enemyTarget != null)
            {
                Vector3 targetPosition = enemyTarget.GetPosition();
                if (chargeDelay > 0)
                {
                    // Too soon to charge, move to it
                    enemyMain.EnemyPathfindingMovement.MoveToTimer(targetPosition);
                    //Debug.Log(enemyMain.EnemyPathfindingMovement);
                }
                else
                {
                    if (CanChargeToTarget(targetPosition, enemyTarget.GetGameObject()))
                    {
                        chargeDir = (targetPosition - GetPosition()).normalized;
                        SetAimTarget(targetPosition);
                        ShowAim();
                        chargeSpeed = 200f;
                        enemyMain.EnemyPathfindingMovement.Disable();
                        characterBase.PlayDodgeAnimation(chargeDir);
                        state = State.Charging;
                    }
                    else
                    {
                        // Cannot see target, move to it
                        enemyMain.EnemyPathfindingMovement.MoveToTimer(targetPosition);
                    }
                }
            }
            break;

        case State.Charging:
            float chargeSpeedDropMultiplier = 1f;
            chargeSpeed -= chargeSpeed * chargeSpeedDropMultiplier * Time.deltaTime;

            float        hitDistance  = 3f;
            RaycastHit2D raycastHit2D = Physics2D.Raycast(GetPosition(), chargeDir, hitDistance, 1 << GameAssets.i.playerLayer);
            if (raycastHit2D.collider != null)
            {
                Player player = raycastHit2D.collider.GetComponent <Player>();
                if (player != null)
                {
                    player.Damage(enemyMain.Enemy, .6f);
                    player.Knockback(chargeDir, 5f);
                    chargeSpeed = 60f;
                    chargeDir  *= -1f;
                }
            }

            float chargeSpeedMinimum = 70f;
            if (chargeSpeed < chargeSpeedMinimum)
            {
                state = State.Normal;
                enemyMain.EnemyPathfindingMovement.Enable();
                chargeDelay = 1.5f;
                SetStateNormal();
                HideAim();
            }
            break;

        case State.Attacking:
            break;

        case State.Busy:
            break;
        }
    }