- Home /
Ortho camera viewport setup?
Everything I've found on this seems either way more complicated than what I am looking for, or specifically for a scrolling/moving camera, which also isn't what I need.
I am trying to set up a plane and camera. I want the viewport of the camera to give me a 960x640 view.
Right now I have a plane GameObject set up like this: Pos: 480, 0, 320 Rot: 0, 0, 0 Scale: 96, 0, 64
and a MainCamera set up like this: Pos: 480, 320, 320 Rot: 90, 0, 0 Scale: 1, 1, 1 Projection: Orthographic Size: 572 Normalized View Port Rect: X=0, Y=0, W=1, H=1
What I would like to have is a view of the plane, with the camera rendering a 960x640 view. I'd like to be able to place objects in this view at a 1:1 pixel ratio. It would be great if I could have it set up so that if I instantiate an object, I can place it at a position using the viewport's screen coordinates (I'd prefer bottom left being (0,0), but anything logical would work, really.
What settings should I be looking at to set the plane object and the camera object up to do this?
Many thanks in advance (and if anyone has pointers to any basic tutorials on things similar to this, I'd love to see them).
--Gray
Answer by DaveA · May 13, 2011 at 10:42 PM
This may help somewhat: http://unity3d.com/support/documentation/ScriptReference/Camera.ViewportToScreenPoint.html
also http://unity3d.com/support/documentation/ScriptReference/Camera-orthographicSize.html
Answer by Bunny83 · May 14, 2011 at 12:45 AM
Well, the orthographic camera's aspect ratio is adjusted by the actual resolution. I'm a bit confused, do you want to work on the x-z-plane or why does your camera looks "downwards"? ... Anyway, just follow these steps:
- Set your project resolution to 960x640 in the project settings.
- Set your camera's orthographicSize to 320 (half height)
- If you want to work on the x-z-plane with the origin (0,y,0) at the bottom left just move your camera and your plane to 480,y,320
- Make sure the plane have a lower y value than the camera.
- Actually that's it. In the editor you should select the project resolution (affects the aspect ratio) in the drop-down-field at the top left of your game-view.
If you set it up that way x==0 z==0 is at the bottom left of the screen and x==960 z==640 is at the top right.
ps. The plane (unity default plane) is set up like you've done above but y-scale = 1. localScale == 96, 1, 64 (don't set a scale to 0 if it doesn't matter keep the 1 ;))
You could also parent your camera to the plane, that way the camera sits at 0,dist,0 where dist is the distance from your plane which should be positive.
See below for more detail, not enough room in Comments to do so... --Gray
Answer by Gray · May 16, 2011 at 10:19 PM
As for why the camera looks "downwards"... I'm really new to this, and ...well... it just ended up that way, heh. I'm not married to that, but it seems kind of a pain to change everything.
I went back and fiddled about, using your advice above, and even went so far as to create a brand new scene, with a camera, lightsource, and newly-created plane. I have a simple script attached to the plane that when you click on the plane, it uses Debug.Log to spit out the coords that you clicked on.
Using this, what seems to be happening both in the new scene, and in the old scene is that while I would expect clicking in the bottom left of the screen would generate something like (0, 0, 0), while clicking on the top right would produce (960, 640, 0). What I am actually seeing is that the bottom left does give (0, 0, 0), but the top right is giving (1116.0, 744.5, 0). And I really am at my wits end to figure out why.
I also have some "tiles" that are placed in the scene. These tiles are simply Cube GameObjects, Scaled (100, 1, 100) with a 100x100 texture on them. The idea is to build a set of these on the right side, the user clicks one, then clicks somewhere in the viewport and if there isn't already a tile there, it moves it there. I can place them along the right side fine, but they all seem to be 115x115 now, which I am sure is another symptom of whatever I am seeing/not understanding, above.
--Gray
I can't reproduce that. I get exactly what you would expect. Are you sure that you set your project resolution to 960x640 and set the gameview resolution to the project resolution? If you hve done this you gameview should have black bars top/bottom or left/right to make sure the resolution matches the one you've configured. If you just set an aspect-ratio the gameview's size will be different. I've also created a cube and tested the border coordinates. everything is fine... Btw. you can edit your question if you want to change/add information ;)
Thank you so much, that was the problem. I didn't realize there was a separate setting for the Game view. Setting it to Standalone (960x640) makes it work exactly like I wanted it to. Again, thank you very much, this has been frustrating me for over a week.
--Gray
Your answer
Follow this Question
Related Questions
How does the aspect ratio work? 0 Answers
Center Object in Viewport 1 Answer
Prevent objects from disappearing when zooming in on an orthographic scene? 1 Answer
How to get a camera to render to render texture at a custom aspect ratio. 1 Answer
Why Is My Orthographic Camera Not Rendering at the Full Resolution? 1 Answer