How to see computer move?

Inside my Update method i have:

        if (playerTurn)
        {
            Camera.main.transform.position = new Vector3(40, 12.5f, -6);
            playerAttack(); //Select tile to attack
        }
        else
        {
            Camera.main.transform.position = new Vector3(-1.7f, 12.5f, -6);
            computerAttack(); //Select one random tile
            playerTurn = true;
            playerCanAttack = true;
        }

So i have two different tile grids. When it’s player’s turn, the Camera is focused on the enemy’s grid to select a tile to attack. When it’s computer’s turn the Camera will focus on player’s grid to select a random tile to attack.
Because the player has to give an Input (from mouse) to attack a tile, the Camera will be focused on the enemy’s grid. However, because the computer does the attack so fast, the Camera still remains on enemy’s grid (It focuses on player’s grid for less than a second and it goes back to the enemy’s grid). Any help?

This sort of turn-based behavior takes a some effort make.

What you will basically need is some kind of “game director” system that controls various states of the game.

For instance, a complete turn might look like:

  • enable player input
  • tell the player you’re ready for their input (“Your turn!”)
  • waiting for player to move:
    → accept the player’s move (swipe? tap? keypress? button?)
    → let the player scroll around and see more before deciding?
    → let the player other other UI (check inventory, etc.)
  • validate that the player’s attempted move is acceptable
  • visualize the player’s inputted move (smoothly)
  • end the player’s turn (visuals or text perhaps?)
  • disable player input
  • tell the player that the computer is moving “COMPUTER MOVE!”
  • decide what piece the computer will move
  • smoothly transition camera to computer’s piece
  • show computer piece moving smoothly
  • show any results (combat, win, loss, hurrah, yay)
  • transition camera back to where player left it
  • go back to the top (unless there are multiple computer players, then loop)

A state machine is the most common approach for this.

You can keep the above steps in mind and go play an existing turn-based game and you will get a feel for how to understand what their “game director” is doing.

1 Like