- Home /
How do I keep an Ortho camera in a specific range when the ortho changes?
I have an Othrographic camera which is set to something like 260. As the user gestures ( this is on the iPhone ) the ortho size of the camera changes to provide a zoom in/zoom out affect. Not only can the user zoom in and out but they can also move the camera around ( like when zoomed in for instance ). What I am trying to do is not all the camera to move when at the max ortho ( 260 ) but as they zoom in, the user can move the camera but only within the bounds of the world provided.
In thinking about this, I really couldn't come up with a way seeing how the rect of the camera is always 0,0,1,1.
I am hoping someone can provide some insight! Thanks in advance.
Answer by Ashkan_gc · Dec 25, 2009 at 11:36 AM
you can use normal cameras and move them to zoom in and out. if you want to have something always in your view, you can use the OnBecameInvisible function and move back the camera to it's previous position. but if you want to have some points always in view you can check their screen space position.
Ortho is being used to give the look desired to render the view (more 2D using 3D elements).
Answer by yo.ian.g · Dec 28, 2009 at 03:40 AM
Similar to what Ashkan suggested you can use Camera.ScreenToWorldPoint to test that your screen corners would be within your viewable world space when the user attempts to move the camera.
This means you have to somehow define the bounds of your world, whether by finding the min and max location of all objects in your scene or by manually storing them.
Personally I would manually create an invisible box in each scene that encompasses the viewable world space and test against it.
Thanks! I went with what you both suggested and switched the camera from Ortho.
Answer by pkamat · Dec 25, 2009 at 10:23 AM
Can you give more info on how the camera movement is (FPS, Free form, etc)? I assume you want the camera to always look at the center of the world and when the user moves left of right the camera would rotate around the world y-axis. is that rite?
Also you dont need to change the Ortho size to zoom in and out..
It is free form where the player is watching the events going on (sort of like a simulation) versus any direct interaction. The camera does not always look at the center of the world and does not focus on any single item in the world. There is no turning of the camera. The Ortho is being used to give a 2d effect. when they zoom in they see what is in their view and can move the camera around to see other parts of the map.
Thanks.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Keeping the camera in bounds 1 Answer
Backgrounds moving at different speeds? 1 Answer
Fitting Bounds into Orthographic 2d Camera. 2 Answers
Pan Orthographic Camera? 2 Answers