- Home /
Zoom out in orthographic view?
hey guys, im working on a 2d side scroller based on the 2d tutorial. im working with 2d assets and using sprite manager to deal with the animation. I want to use the zoom features that is set up in the tutorial. it sets the camera distance on certain positions, but when I switch the view to orthographic the distance gets replaced with orthographic size...
so my question is this. dose anyone know what I should change in the code to get the camera to zoom out in orthographic mode?
ive tried to change the camera distance part to orthographic size but it was not it, at least not just that.
the reason for using orthographic view is that Im running into trouble with the assets that are in front and in the back, they are jumping around the z axis, it seems to be something unity dose to give a more realistic sense of depth.
Answer by duck · Apr 16, 2010 at 11:35 AM
The orthographicSize property of your camera actually is the correct value to change in order to zoom in and out when your camera is in orthographic mode.
Changing the orthographic size of your camera shouldn't affect anything else in your scene - i.e. it shouldn't cause anything to "jump around on the z axis", it should simple crop or expand your view to show a smaller or larger area.
This is very different from actually moving your camera closer or further from your object. You don't need to actually move the camera at all while you're doing this.
If this doesn't solve your problem, you might have to describe more clearly the problems that you're having with things "jumping around".
thanks for the you comment, ive gotten it to work now but the thing is, its jumping from one "zoom" to the other, is there a way to make it smooth, like when your moving the camera in closer ?
$$anonymous$$ake the change in orthographic size more gradual, it doesn't need to be whole numbers. Also you can multiply the change by deltatime to make the zoom relative to real time rather than number of cycles.
One think you could to to implement a smooth orthographic camera size zoom is by using code similar to this:
zoomTimePassed += Time.deltaTime;
float t = zoomTimePassed / TOTAL_ZOO$$anonymous$$_TI$$anonymous$$E;
camera.main.orthograhicSize = $$anonymous$$athf.SmoothStep(initialZoom, newZoom, t);
Note that I haven't tested this code, but it should convey the idea of how it could be done.
The SmoothStep function will smoothly change the zoom, without any abrupt changes in the speed at which the zoom is changed.
I know this is an old post but thank you! I was having trouble with this also. I had worked out that $$anonymous$$athf.smoothStep was needed, but I couldn't get it to work nicely. This code snippet worked perfectly for me! :)
Answer by allesisda · Apr 25, 2012 at 08:16 PM
i have a problem with zooming in orthografic view:
i build my HUD with gameobjects, and if i change dthe orthographic size i get super small/big HUD elements...
is there a simple way to scale them together with the O-size?
You'll likely have to have your game area and HUD rendered using two separate cameras.