- Home /
How do you zoom with an orthographic camera?
From looking at the documentation and other questions I do:
Camera.main.orthographicSize *= scaleFactor
but the view displayed does not change.
I've checked that Camera.main.orthographic
is true
.
Using Debug.Log
I've verified that I've changed the value a lot, in the range from 1 to 1000 and still I see no change in how the game looks. If I run the game in the editor and change the Size in the Inspector, it doesn't change how much is displayed either.
How do I get zoom to work in orthographic projection?
Very strange. You should test in a new scene, because what you describe should work. Any chance you are using more than one camera? Camera.main denotes the camera with the tag '$$anonymous$$ainCamera', not the camera currently being used. Note you may want a linear zoom rather than a geometric one.
Doesn't it really change anything when you modify the size value in the inspector? For me it works fine. The larger you make the size, the more will be displayed.
I like how you answer your own question on the 2nd line, then go on to explain the real problem (which is you can't get it to work.)
I'd go with ...orthoSize *= startSize*scale
, once you get it working. That way you can reset scale to 1 to go back to starting size.
I found out why it wasn't working. It seems that the orthographicSize value is ignored if you've set a custom projection matrix. The custom matrix I had set was orthographic, but I guess Unity didn't know that.
Hah! Yes, that is the definition of a custom projection matrix.
All of the camera ortho/FoV settings go into making a projection matrix, which goes on to make the camera view. By definition, making your own overrides camera settings (the docs even more-or-less say this.)
Answer by DajBuzi · Jul 24, 2014 at 08:53 AM
Hello,
You i think that you need to make reference to the camera instead of getting it from the Camera class. Here is working example on how to do this:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
Camera cam;
public void Start()
{
cam = this.camera;
}
public void Update()
{
if(Input.GetKey(KeyCode.KeypadPlus))
cam.orthographicSize -= .1f;
if(Input.GetKey(KeyCode.KeypadMinus))
cam.orthographicSize += .1f;
}
}
Regards, M.Rogalski
But the point of Camera.main
is so you can have the script anywhere. This script would need to be on the camera (for this.camera
to work.)
A direct reference from anywhere could use public Camera theCam;
, with the camera dragged into the Inspector slot.
But, but, finding the camera doesn't seem to be the OP's problem (see the 2-sentence paragraph -- orthoSize is being changed.)
Your answer
Follow this Question
Related Questions
Trying to use an orthographic camera in interior scenes 0 Answers
zoom in with orthografic camera with focus on the a specific point 0 Answers
How to use ScreenPointToRay for orthographic cameras 1 Answer
2D camera zoom in comparison to the height of target 2 Answers
How to make WorldToScreenPoint work with an orthographic camera? 1 Answer