- Home /
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.)
Adjusting the camera's view via Camera.orthographicSize
Adjusting the map's scale via GameBoardObj.transform.localScale
Other
Answer by whydoidoit · Apr 11, 2013 at 06:04 AM
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 $$anonymous$$d 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 2DT$$anonymous$$ 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?
Answer by fafase · Apr 11, 2013 at 06:13 AM
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)
Your answer
![](https://koobas.hobune.stream/wayback/20220613100108im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Orthographic camera zoom towards transform 1 Answer
Touch code for panning and zooming not working 1 Answer
Pixel Perfect Camera Component 128 ppu pixel is too zoomed in for builds 1 Answer
Zooming in and out with an orthographic camera, while the bottom edge is fixed. 0 Answers
Why is my orthographic camera not resizing according to resolution / aspect? 0 Answers