Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Curyous · Jul 24, 2014 at 02:19 AM · camerazoomorthographicorthographic camera

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?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Jul 24, 2014 at 02:26 AM 1
Share

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.

avatar image Razacx · Jul 24, 2014 at 02:27 AM 0
Share

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.

avatar image Owen-Reynolds · Jul 24, 2014 at 03:22 AM 0
Share

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.

avatar image Curyous · Mar 02, 2015 at 08:05 PM 0
Share

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.

avatar image Owen-Reynolds · Mar 02, 2015 at 09:09 PM 0
Share

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.)

1 Reply

· Add your reply
  • Sort: 
avatar image
3

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Jul 24, 2014 at 03:35 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges