E
E
Egor2013-09-24 18:53:51
Unity
Egor, 2013-09-24 18:53:51

Zoom cameras in a 2D game?

I want to zoom in and out on a background in a 2D game. The camera in orthogonal mode is aimed at the background sprite (using the 2d toolkit), sprite in original size without scaling. The minimum zoom value will be the size of the camera, at which the sprite will fill the entire screen with cropping in height. Maximum - a certain hardcode or coefficient as a percentage of the minimum.
I can't figure out how to calculate the size value for the minimum zoom, while I know the screen and background sizes.
Should the camera view port be changed for different screen aspect ratios?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor, 2013-09-26
@ese

I'll answer my own question.
minCameraSize = ((backSprite.renderer.bounds.size.x) / backCamera.aspect) / 2;
backCamera.orthographicSize = minCameraSize;

M
m08pvv, 2013-09-24
@m08pvv

Have you looked at the answers.unity3d.com forum?
Zoom out in orthographic view
On side scroller 2d, camera zoom out when jumping
2D camera zoom in comparison to the height of target

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question