Exemplo n.º 1
0
    private void HandleMoving(float time)
    {
        // Increment timer.
        moveTimer += time;

        // Move it to it's destination.
        ControllingEnemy.SetMoveDirection(MoveDirection);

        // If the duration for moving is reached
        if (moveTimer >= ControllingEnemy.MoveDuration)
        {
            // If the enemy just started stopping. (Stop moving slowly.)
            if (progress <= 1)
            {
                // Determine the velocity when the enemy started slowing down.
                Vector2 startVel = MoveDirection * ControllingEnemy.Speed;
                ControllingEnemy.Velocity = Vector2.Lerp(startVel, Vector2.zero, progress);

                // Increment progress.
                progress += time * 1.25f;
            }
            else
            {
                progress = 0f;

                // This enemy is now lingering.
                isMoving    = false;
                isLingering = true;
                // Ensures that this enemy can now shoot
                canShoot = true;
                // Ensures this enemy stays
                ControllingEnemy.SetMoveDirection(Vector2.zero);
            }
        }
    }
Exemplo n.º 2
0
    public HitRunAI(Enemy controlledEnemy, Direction moveDirection) : base(controlledEnemy)
    {
        moveTimer = lingerTimer = 0f;
        progress  = 0f;

        isMoving  = true;
        isRunning = isLingering = false;

        canShoot = !ControllingEnemy.ShootAfterMoving;

        MoveDirection = moveDirection.ToVector2();
        ControllingEnemy.SetMoveDirection(MoveDirection);
    }
Exemplo n.º 3
0
    private void HandleRunning(float time)
    {
        // If the enemy just started running. (Start moving slowly.)
        if (progress <= 1)
        {
            // Determine the velocity this enemy should reach.
            Vector2 finalVelocity = -MoveDirection * ControllingEnemy.Speed;
            ControllingEnemy.Velocity = Vector2.Lerp(Vector2.zero, finalVelocity, progress);

            // Increment progress.
            progress += time * 1.25f;
        }
        else
        {
            ControllingEnemy.SetMoveDirection(-MoveDirection);
        }
    }
    private void HandleMovement(float time)
    {
        // If the enemy has yet to pass by the player.
        if (!passedPlayer)
        {
            // Get direction to player
            Vector2 direction = (playerTransform.position - ControllingEnemy.transform.position).normalized;

            float rotateAmt = Vector3.Cross(direction, ControllingEnemy.transform.up).z;

            Vector2 finalDirection = (direction * (rotateAmt * ControllingEnemy.Speed)).normalized;

            // Move this enemy towards the player.
            ControllingEnemy.SetMoveDirection((playerTransform.position - ControllingEnemy.transform.position).normalized);

            // check if the enemy has passed by the player.
            if (ControllingEnemy.transform.position.y <= playerTransform.position.y)
            {
                passedPlayer = true;
            }
        }
    }
 private void SetMoveDirection(Vector2 moveDirection)
 {
     MoveDirection = moveDirection;
     ControllingEnemy.SetMoveDirection(MoveDirection);
 }
 public LinearMoveAI(Enemy controlledEnemy, Direction moveDirection) : base(controlledEnemy)
 {
     MoveDirection = moveDirection.ToVector2();
     ControllingEnemy.SetMoveDirection(MoveDirection);
 }