private void ShootTarget()
        {
            enemyTarget = enemyMain.EnemyTargeting.GetActiveTarget();
            if (enemyTarget != null)
            {
                // Shoot!
                Vector3 targetPosition = enemyTarget.GetPosition();

                SetStateAttacking();
                aimAnims.ShootTarget(targetPosition, SetStateNormal);
            }
        }
Esempio n. 2
0
    private void ShootTarget()
    {
        enemyTarget = enemyMain.EnemyTargeting.GetActiveTarget();
        if (enemyTarget != null)
        {
            // Shoot!
            Vector3 targetPosition = enemyTarget.GetPosition();

            SetStateAttacking();
            fireRate        = FIRE_RATE;
            targetPosition += UtilsClass.GetRandomDir() * UnityEngine.Random.Range(-5f, 15f);
            aimAnims.ShootTarget(targetPosition, () => { });
        }
    }
Esempio n. 3
0
        private void Update()
        {
            switch (state)
            {
            case State.Normal:
                enemyTarget = enemyMain.EnemyTargeting.GetActiveTarget();
                if (enemyTarget != null)
                {
                    Vector3 targetPosition = enemyTarget.GetPosition();
                    enemyMain.EnemyPathfindingMovement.MoveToTimer(targetPosition);
                    float attackDistance = 80f;
                    float targetDistance = Vector3.Distance(GetPosition(), targetPosition);
                    if (targetDistance < attackDistance)
                    {
                        // Target within attack distance
                        //int layerMask = ~(1 << GameAssets.i.enemyLayer | 1 << GameAssets.i.ignoreRaycastLayer | 1 << GameAssets.i.shieldLayer);
                        int          layerMask    = ~0;
                        RaycastHit2D raycastHit2D = Physics2D.Raycast(GetPosition(), (targetPosition - GetPosition()).normalized, targetDistance, layerMask);
                        if (raycastHit2D.collider != null && raycastHit2D.collider.GetComponent <Player>())
                        {
                            // Player in line of sight
                            enemyMain.EnemyPathfindingMovement.Disable();
                            SetStateAttacking();
                            Vector3 targetDir = (targetPosition - GetPosition()).normalized;
                            characterBase.PlayPunchAnimation(targetDir, (Vector3 hitPosition) => {
                                // Throw rock
                                enemyTarget = enemyMain.EnemyTargeting.GetActiveTarget();
                                if (enemyTarget != null)
                                {
                                    Vector3 throwDir            = (enemyTarget.GetPosition() - hitPosition).normalized;
                                    EnemyShuriken enemyShuriken = EnemyShuriken.Create(enemyMain.Enemy, hitPosition, throwDir);
                                }
                                //CMDebug.TextPopup("#", hitPosition);
                            }, () => {
                                // Punch complete
                                enemyMain.EnemyPathfindingMovement.Enable();
                                SetStateNormal();
                            });
                        }
                    }
                }
                break;

            case State.Attacking:
                break;

            case State.Busy:
                break;
            }
        }
Esempio n. 4
0
        private void Update()
        {
            switch (state)
            {
            case State.Normal:
                enemyTarget = enemyMain.EnemyTargeting.GetActiveTarget();
                if (enemyTarget != null)
                {
                    state        = State.AimingAtTarget;
                    bulletsFired = 0;
                    aimingShoot.StartAimingAtTarget(enemyTarget.GetPosition(), 20f, 0f, 10f, ShootTarget);
                }
                break;

            case State.AimingAtTarget:
                enemyTarget = enemyMain.EnemyTargeting.GetActiveTarget();
                if (enemyTarget != null)
                {
                    Vector3 targetPosition = enemyTarget.GetPosition();
                    aimAnims.SetAimTarget(targetPosition);
                    aimingShoot.UpdateAimShootAtTarget(targetPosition);
                }
                break;

            case State.Attacking:
                fireRate -= Time.deltaTime;
                if (fireRate <= 0f)
                {
                    TestContinueShooting();
                }
                break;

            case State.Busy:
                break;
            }
        }
Esempio n. 5
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;
        }
    }
        private void Update()
        {
            switch (state)
            {
            case State.Normal:
                enemyTarget = enemyMain.EnemyTargeting.GetActiveTarget();
                if (enemyTarget != null)
                {
                    state = State.AimingAtTarget;
                    aimingShoot.StartAimingAtTarget(enemyTarget.GetPosition(), START_AIM_ANGLE, 0f, 10f, ShootTarget);

                    /*
                     * float attackRange = 50f;
                     * Vector3 targetPosition = enemyTarget.GetPosition();
                     * if (Vector3.Distance(GetPosition(), targetPosition) < attackRange) {
                     *  // Shoot Target
                     *  enemyMain.EnemyMovement.StopMoving();
                     *  characterBase.SetAimTarget(targetPosition);
                     *
                     *  if (Time.time >= nextShootTime) {
                     *      // Can shoot
                     *      nextShootTime = Time.time + FIRE_RATE;
                     *      targetPosition += UtilsClass.GetRandomDir() * UnityEngine.Random.Range(0f, 20f);
                     *      SetStateAttacking();
                     *      characterBase.ShootTarget(targetPosition, SetStateNormal);
                     *  }
                     * } else {
                     *  // Move to Target
                     *  enemyMain.EnemyMovement.SetTargetPosition(targetPosition);
                     *  characterBase.SetAimTarget(targetPosition);
                     * }
                     */
                }
                break;

            case State.AimingAtTarget:
                enemyTarget = enemyMain.EnemyTargeting.GetActiveTarget();
                if (enemyTarget != null)
                {
                    Vector3 targetPosition = enemyTarget.GetPosition();
                    aimAnims.SetAimTarget(targetPosition);
                    aimingShoot.UpdateAimShootAtTarget(targetPosition);

                    /*
                     * aimingShoot.AimAtPosition(targetPosition);
                     * aimAnims.SetAimTarget(targetPosition);
                     *
                     * float aimSpeed = 10f;
                     * aimingShoot.SetAimAngle(aimAngle - aimSpeed * Time.deltaTime);
                     *
                     * aimingShoot.SetAimColor(Mathf.Lerp(.0f, 1.1f, 1 - aimAngle / START_AIM_ANGLE));
                     *
                     * float shootAngle = 0f;
                     * if (aimAngle <= shootAngle) {
                     *  // Shoot!
                     *  SetStateAttacking();
                     *  aimAnims.ShootTarget(targetPosition, SetStateNormal);
                     *  aimingShoot.HideAim();
                     * }
                     */
                }
                break;

            case State.Attacking:
                break;

            case State.Busy:
                break;
            }
        }