- Home /
2D: Camera Size, in Orthographic Projection vs Scale of a Plane
I want to make a 2D game, and I've set the camera up with Orthographic projection. Now I want to add a plane in front of that camera to use as a background for the game. The camera has a size setting, which affects the size of my plane. The plane also has a scale setting, which does the same thing (by the looks of it). These two settings, however, don't seem to work well together. For example, I've set my camera to have a size of 10, and my plane to have a scale of 1 x 1 x 1. This scale makes the camera much larger than what I would like for it to be. I thought if the scale of the plane was the same as the camera size, that the plane would fit perfectly into the camera view. I have a feeling that I have no idea what I'm doing. Could someone please help me out here? Thanks :)
Answer by Owen-Reynolds · May 26, 2013 at 02:51 PM
"These two settings, however, don't seem to work well together." Yes, but not a big deal.
It's just math. The Ortho camera scale is how far it goes both ways, so a scale of 10 shows you a 20-wide chunk of scene. The basic Unity plane just happens to be 10x10. That's sort of odd, since everything else (cubes, spheres) is 1x1. But most people probably want a big plane for backgrounds, walls or floors.
Just pick a size. If you want to aim at 0-5, set the cam at x=2.5 and Size=2.5. Then do the plane. Since it's size 10, scale by 1/2 to get a width of 5.
For fun, measure things out. Can be handy to make reference cubes (maybe color them red and make them long and thin. Bring them to the sides of what the cam sees and check values (does a Size 5 cam really see from -5 to 5?) Can measure the plane width using them.
Answer by robertbu · May 26, 2013 at 02:53 PM
'Orthographic Size' is half of the vertical size of the camera view. You can get the half horizontal size by multiplying the vertical size by Screen.width/Screen.height. So:
var verticalSize = Camera.main.orthographicSize * 2.0;
var horizontalSize = verticalSize * Screen.width / Screen.height;
Object size and object scale are not the same thing. Scale simply scales up or down whatever the size of the mesh. If you are using the build-in plane, the size in world units with a scale of (1,1,1) is 10 x 10.
For experimentation, make sure the camera 'Y' is set to 0. Place a cube at the origin and size it to be twice the Orthographic Size. Note the build-in cube does have a size of 1x1x1 when the scale is (1,1,1).
You might also be interested in the CreatePlane script. It allows you to create a plane with a base size of 1x1 and also with a vertical presentation when the rotation is (0,0,0).