Example #1
0
    void FixedUpdate()
    {
        if (VisibleObject.IsVisible && Player)
        {
            RotateTowardsPlayer(Time.deltaTime);

            transform.position += new Vector3(Random.Range(-5f, 5f), Random.Range(-5f, 5f), 0) * Time.deltaTime;

            ShotCooldown -= Time.deltaTime;
            if (ShotCooldown <= 0)
            {
                Instantiate(Burst, LookAhead.transform.position, transform.rotation, transform.parent);
                Vector2        direction = Vector2Utils.Vector2FromAngle(Body.rotation + Random.Range(-15f, 15f));
                ShotController shot      = Instantiate(Shot, LookAhead.transform.position, transform.rotation, transform.parent).GetComponent <ShotController>();
                shot.Fire(direction, Body.velocity, ShootPower);

                ShotCooldown = MaxShootCooldown + Random.Range(-0.15f, 0.15f);
            }
        }
    }
Example #2
0
    void FixedUpdate()
    {
        Vector2 direction = Vector2Utils.Vector2FromAngle(Rigidbody.rotation);

        if (DesiredMovement > 0)
        {
            // Set drag to give the ship a terminal velocity
            Rigidbody.drag = MovementDrag;

            Rigidbody.AddForce(
                DesiredMovement *
                AccelerationFactor *
                Time.deltaTime *
                BaseAcceleration *
                direction
                );

            if (AccelerationFactor > 0 && TailParticleSystem.isStopped)
            {
                TailParticleSystem.Play();
            }
        }
        else
        {
            Rigidbody.drag = 0;

            if (TailParticleSystem.isPlaying)
            {
                TailParticleSystem.Stop();
            }
        }

        Rigidbody.AddTorque(
            BaseTorque * Time.deltaTime * DesiredRotation * TorqueFactor
            );

        if (DesiredRotation != 0 && TorqueFactor > 0)
        {
            if (DesiredRotation > 0)
            {
                if (LeftParticleSystem.isStopped)
                {
                    LeftParticleSystem.Play();
                }
                if (RightParticleSystem.isPlaying)
                {
                    RightParticleSystem.Stop();
                }
            }
            else
            {
                if (RightParticleSystem.isStopped)
                {
                    RightParticleSystem.Play();
                }
                if (LeftParticleSystem.isPlaying)
                {
                    LeftParticleSystem.Stop();
                }
            }
        }
        else
        {
            if (LeftParticleSystem.isPlaying)
            {
                LeftParticleSystem.Stop();
            }
            if (RightParticleSystem.isPlaying)
            {
                RightParticleSystem.Stop();
            }
        }

        ShotCooldown -= Time.deltaTime;
        if (ShotCooldown <= 0 && Shoot && ShootFactor > 0f)
        {
            if (BlasterParts[0].activeSelf)
            {
                foreach (var cannon in CannonControllersLevel1)
                {
                    cannon.Fire(direction, Rigidbody.velocity);
                }
            }
            if (BlasterParts[1].activeSelf)
            {
                foreach (var cannon in CannonControllersLevel2)
                {
                    cannon.Fire(direction, Rigidbody.velocity);
                }
            }
            if (BlasterParts[2].activeSelf)
            {
                foreach (var cannon in CannonControllersLevel3)
                {
                    cannon.Fire(direction, Rigidbody.velocity);
                }
            }

            Rigidbody.AddForce(BaseRecoil * Mathf.Exp(ShootFactor) * direction);

            Shake();

            ShotCooldown = ShotCooldownTime;
        }

        UpdateSpecialAttackTimer(SpecialAttackTimer + Time.deltaTime);

        if (SpecialAttackTimer >= MaxSpecialAttackTimer)
        {
            if (ExecuteSpecialAttack)
            {
                SpecialAttackController specialAttackController = Instantiate(SpecialAttack, transform.position, transform.rotation, transform.parent).GetComponent <SpecialAttackController>();

                specialAttackController.Fire(gameObject, WorldController);

                Shake(SpecialAttackController.Duration);
                WorldController.Flash(2);
                UpdateSpecialAttackTimer(0f);
            }
        }

        UpdateCameraZoom(Rigidbody.velocity.magnitude);
    }