示例#1
0
    protected virtual void Fire(RangedWeaponConfiguration firingConfiguration)
    {
        Bullet bullet = ObjectRecycler.Singleton.GetObject <Bullet>(firingConfiguration.BulletID);

        bullet.hit.source = enemy;
        bullet.isFriendly = false;


        LinearMovement bulletMovement = bullet.GetComponent <LinearMovement>();

        bulletMovement.speed           = firingConfiguration.BulletSpeed;
        bulletMovement.initialPosition = firingConfiguration.Muzzle ? firingConfiguration.Muzzle.position : enemy.transform.position;
        bulletMovement.orientation     = (enemy.currentTarget.transform.position - bulletMovement.initialPosition).normalized;
        bulletMovement.GetComponent <Bullet>().isFriendly = false;
        bulletMovement.transform.right = bulletMovement.orientation;
        bulletMovement.gameObject.SetActive(true);
    }
示例#2
0
    protected override void Fire(RangedWeaponConfiguration firingConfiguration)
    {
        Bullet bullet = ObjectRecycler.Singleton.GetObject <Bullet>(firingConfiguration.BulletID);

        bullet.hit.source = enemy;
        bullet.isFriendly = false;


        LinearMovement bulletMovement = bullet.GetComponent <LinearMovement>();

        bulletMovement.speed           = firingConfiguration.BulletSpeed;
        bulletMovement.initialPosition = firingConfiguration.Muzzle ? firingConfiguration.Muzzle.position : enemy.transform.position;
        bulletMovement.orientation     = enemy.GetDeviatedBulletDirection(firingConfiguration.MinDeviationAngle, firingConfiguration.MaxDeviationAngle);
        bulletMovement.transform.right = bulletMovement.orientation;
        bulletMovement.gameObject.SetActive(true);


        enemy.isGunCharging = false;


        gunAnimator.Play("L2Drone_Gun_Idle");

        AudioManager.Singleton.PlayOnce("LaserBullet");
    }
示例#3
0
    public override string Update()
    {
        Vector3 enemyPosition = enemy.transform.position;


        animator.speed = TimeManager.Instance.TimeFactor * enemy.UnitTimeFactor;


        if (state_onTargetFound != "")
        {
            PlayerCharacter target = FindAvailableTarget(enemyPosition, enemy[StatisticType.SightRange], enemy.GuardZone);

            if (target)
            {
                enemy.currentTarget = target;


                rigidbody.velocity = Vector2.zero;

                IsMoving = false;


                return(state_onTargetFound);
            }
        }


        float t = Time.time;


        if (enemy.NumPatrolPoints > 0)
        {
            if (t >= t_finishWaiting)
            {
                if (useAStar)
                {
                    if (currentPath != null)
                    {
                        Vector3 wayPoint = currentPath.vectorPath[indexWayPoint];

                        float distance = enemy.Data.Type == EnemyType.Ground ? Mathf.Abs(wayPoint.x - enemyPosition.x) : Vector2.Distance(wayPoint, enemyPosition);

                        if (distance < 0.5f)
                        {
                            ++indexWayPoint;
                        }


                        if (indexWayPoint >= currentPath.vectorPath.Count)
                        {
                            rigidbody.velocity = Vector2.zero;

                            IsMoving = false;


                            t_finishWaiting = t + enemy.GetPatrolPointStayTime(indexTargetPatrolPoint);


                            indexLastPatrolPoint   = indexTargetPatrolPoint;
                            indexTargetPatrolPoint = (indexTargetPatrolPoint + 1) % enemy.NumPatrolPoints;


                            seeker.StartPath(enemy.transform.position, enemy.GetPatrolPoint(indexTargetPatrolPoint));
                            currentPath = null;
                        }
                        else
                        {
                            Vector2 direction = (currentPath.vectorPath[indexWayPoint] - enemy.transform.position).normalized;

                            if (enemy.Data.Type == EnemyType.Ground)
                            {
                                direction = direction.x > 0 ? Vector2.right : Vector2.left;
                            }


                            enemy.Turn(direction);


                            rigidbody.velocity = direction * speed * TimeManager.Instance.TimeFactor * enemy.UnitTimeFactor;
                            IsMoving           = true;
                        }
                    }
                }
                else
                {
                    Vector3 patrolPoint = enemy.GetPatrolPoint(indexTargetPatrolPoint);

                    switch (enemy.Data.Type)
                    {
                    case EnemyType.Ground:
                    {
                        float dx = patrolPoint.x - enemyPosition.x;

                        if (Mathf.Abs(dx) < 0.5f)
                        {
                            rigidbody.velocity = Vector2.zero;

                            IsMoving = false;


                            t_finishWaiting = t + enemy.GetPatrolPointStayTime(indexTargetPatrolPoint);


                            indexLastPatrolPoint   = indexTargetPatrolPoint;
                            indexTargetPatrolPoint = (indexTargetPatrolPoint + 1) % enemy.NumPatrolPoints;
                        }
                        else
                        {
                            Vector3 direction = dx > 0 ? Vector2.right : Vector2.left;


                            enemy.Turn(direction);


                            rigidbody.velocity = speed * direction;

                            IsMoving = true;
                        }
                    }
                    break;


                    case EnemyType.Floating:
                    {
                        Vector3 v = patrolPoint - enemyPosition;

                        if (v.magnitude < 0.5f)
                        {
                            rigidbody.velocity = Vector2.zero;

                            IsMoving = false;


                            t_finishWaiting = t + enemy.GetPatrolPointStayTime(indexTargetPatrolPoint);


                            indexLastPatrolPoint   = indexTargetPatrolPoint;
                            indexTargetPatrolPoint = (indexTargetPatrolPoint + 1) % enemy.NumPatrolPoints;
                        }
                        else
                        {
                            Vector3 direction = v.normalized;


                            enemy.Turn(direction);


                            rigidbody.velocity = speed * direction;

                            IsMoving = true;
                        }
                    }
                    break;
                    }
                }
            }
        }


        RangedWeaponConfiguration firingConfiguration = enemy.PatrolFiringConfiguration;

        if (firingConfiguration.FiringInterval > 0) // Check if the firing is enabled
        {
            if (enemy.currentTarget == null || !IsPlayerInSight(enemy.currentTarget, 10))
            {
                enemy.currentTarget = FindAvailableTarget(enemy.transform.position, 10, enemy.GuardZone);
            }


            if (enemy.currentTarget)
            {
                if (alwaysFacingTarget)
                {
                    enemy.Turn();
                }


                if (t >= t_nextFire)
                {
                    if (t_finishCharging == 0)
                    {
                        t_finishCharging = t + firingConfiguration.ChargeTime;
                    }


                    if (t >= t_finishCharging)
                    {
                        Fire(firingConfiguration);

                        t_nextFire       = t + firingConfiguration.FiringInterval;
                        t_finishCharging = 0;
                    }
                    else
                    {
                        Charge();
                    }
                }
            }
        }


        return(Name);
    }