What is the best way to zoom a map with an orthographic camera?

This is similar to my previous question in that the game environment is the same: I’m making a 2D board game, the game board is situated such that The Main (orthographic) Camera looks down in the Y axis to see the face of the board. So looking at the board the x axis is left/right (west/east) and the z axis is top/bottom (north/south). The y axis is not used except to initially set the height (distance) of the camera from the board and should never be changed.

The game board is like a large map in that it is bigger than the orthographic camera’s size so in order to see the whole map I have to either change the size of the orthographic camera OR scale the board (‘GameBoardObj’ in the example below).

What is the best way to implement this? (I’m using pinch gestures to zoom in/out of the map.)

  1. Adjusting the camera’s view via Camera.orthographicSize
  2. Adjusting the map’s scale via GameBoardObj.transform.localScale
  3. Other

2 Answers

2

I’d be using the orthographicSize - I wouldn’t mess with your game objects scale (because it can cause problems with collision detection etc if things have colliders and don’t have rigidbodies).

it might be worth bearing in mind that, very often with 2D type games, you'll be using multiple cameras. when you change the size, it will surely screw up other stuff (perhaps any UI, or if you're using 2DTK or the like) so it may well be you have to use another or more cameras, when you do the zoom. ie anything that goes to hell because of the zoom, you'll need to go to a spearate camera for that maybe?

This is what we use for one of our game to Zoom in and out:

if(GUI.RepeatButton (plusButton,"+")){
   if(camera.orthographicSize>= minPos)
      camera.orthographicSize -= Time.deltaTime * speedZoom;
}
if(GUI.RepeatButton (minusButton,"-")){
   if(camera.orthographicSize <= maxPos)
      camera.orthographicSize += Time.deltaTime * speedZoom;
}

(plusButton and minusButton are the Rect)