예제 #1
0
    private void FixedUpdate()
    {
        if (playerControlsEnabled.Toggle)
        {
            if (rotateClockwise)
            {
                flying.RotateCW();
                rotateClockwise = false;
            }
            else if (rotateCounterClockwise)
            {
                flying.RotateCCW();
                rotateCounterClockwise = false;
            }

            if (accelerate)
            {
                flying.Accelerate();
                accelerate = false;
            }
            else if (decelerate)
            {
                flying.Decelerate();
                decelerate = false;
            }
        }
    }
예제 #2
0
    private void FixedUpdate()
    {
        var angleDiff = Vector3.SignedAngle(transform.right, targetDir, Vector3.forward);

        if (angleDiff < -5.0f)
        {
            plane.RotateCW();
        }
        if (angleDiff > 5.0f)
        {
            plane.RotateCCW();
        }

        if (transform.right.x < 0 && !plane.isUpsideDown())
        {
            plane.Roll();
        }

        if (transform.right.x > 0 && plane.isUpsideDown())
        {
            plane.Roll();
        }

        if (plane.throttle < targetThrottle - 0.1f)
        {
            plane.Accelerate();
        }
        if (plane.throttle > targetThrottle + 0.1f)
        {
            plane.Decelerate();
        }

        if (shoot)
        {
            Projectile projectile = shooter.Shoot(transform.right);
            if (projectile != null)
            {
                AudioPlayer.main.PlaySound(GameEvent.EnemyGunFires);
            }
        }

        if (bomb)
        {
            bomber.Drop((Vector2)bomber.transform.position, rb2D.velocity);
            Projectile projectile = shooter.Shoot(transform.right);
            if (projectile != null)
            {
                AudioPlayer.main.PlaySound(GameEvent.EnemyGunFires);
            }
        }
    }
예제 #3
0
    private void FixedUpdate()
    {
        if (rotationOngoing)
        {
            return;
        }

        if (state == AIStates.Start)
        {
            flying.Accelerate();
            if (Vector3.Distance(playerPosition.Value, transform.position) > 50f)
            {
                state = AIStates.PlayerNotInRange;
            }
            else if (playerPosition.Value.y + 1f <= transform.position.y) // player is at least 1 unit lower than this enemy
            {
                state = AIStates.PlayerBelow;
            }
            else
            {
                state = AIStates.PlayerInRange;
            }
        }
        else if (state == AIStates.PlayerNotInRange)
        {
            if (Vector3.Distance(playerPosition.Value, transform.position) <= 50f)
            {
                state = AIStates.PlayerInRange;
            }

            if (transform.position.x > playerPosition.Value.x)
            {
                if (body.velocity.x > 0)
                {
                    //flip
                    //flying.RotateCW(Vector3.Angle(transform.position, playerPosition.Value), callBackFinished, true);
                    flying.RotateCW(playerPosition.Value - transform.position, callBackFinished, true);
                    rotationOngoing = true;
                    Debug.Log("Rotate towards player");
                }
                else
                {
                    flying.Accelerate();
                }
            }
            else if (transform.position.x < playerPosition.Value.x)
            {
                if (body.velocity.x < 0)
                {
                    flying.RotateCW(playerPosition.Value - transform.position, callBackFinished, true);
                    rotationOngoing = true;
                    Debug.Log("Panic!");
                }
                else
                {
                    flying.Accelerate();
                }
            }
        }
        else if (state == AIStates.PlayerInRange)
        {
            if (Vector3.Distance(playerPosition.Value, transform.position) > 50f)
            {
                state = AIStates.PlayerNotInRange;
            }
        }
    }