title: Unity keep the player centered on the screen
body: <p>I started with a little topdown game and want to calculate the camera transform when starting the game.</p>
  
  <p>The camera is not set to 90 degrees, it should have like 70. When rotating it, I need the calculate the difference on Z to keep the player in the middle of the screen.</p>
  
  <pre><code>public Transform player; // player object
  float offsetY = 30; // distance on y
  float rotationAngleX = 70; // rotation when looking down
  
  private void Start()
  {
      player = Globals.GetPlayerObject().transform; // reference
      transform.Rotate(rotationAngleX, transform.rotation.y, transform.rotation.z); // rotate the camera down
      transform.position = new Vector3(player.position.x, player.position.y + offsetY, player.position.z); // move it to the player
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HaCbc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HaCbc.png" alt="img"></a></p>
  
  <p>So what do I need to calculate here, to have the player in the middle? It should always work, so if I change the height on y or rotate the camera by 80 oder 60 degrees, the calculation should work too. </p>
  
  <p>Thanks!</p>