x


Relation between Orthographic camera size and object scale?

I have some objects in my game that are intended to be HUD items. When I zoom out with an orthographic camera by changing the orthographicSize property, I don't want my HUD's size to change. So I thought I'd increase the scale of my HUD as I zoomed out. Is there some magic number I can use to set the scale based on the current orthographicSize property?

more ▼

asked Jun 17 '12 at 09:49 PM

homer_3 gravatar image

homer_3
209 9 19 26

I dont know about the magic number, but you can use multiple cameras and leave the scale alone. just make your HUD camera a child of your main camera. use the culling masks of your hud camera to only show stuff on the HUD layer and the main camera to show everything but the hud. also make sure that the depth of your hud camera is bigger than the main cameras. hope that helps

Jun 17 '12 at 09:56 PM pheash

I had no idea multiple cameras could be used to create a single view. This sounds like a good solution but I've may have run into an issue.

I've added a 2nd camera and made it a child of the main one. I created a layer called HUD and the 2nd camera only has the HUD layer checked, while the 1st has everything but HUD checked. The main camera's depth is -2 and the HUD camera's depth is -1. When I go into my game, I can only see my HUD. What's odd is I can see objects in the main camera's preview while in the edit mode.

I've also tried not having any culling on the main camera and tell it show show everything. But I still only see the HUD layer.

edit: Ok, I found that I needed to set the Clear Flags in the HUD camera to depth only. This works perfect! Thanks!

Jun 17 '12 at 10:14 PM homer_3

Set the HUD camera's "clear flags" to "Don't Clear".

Note that using two cameras is more expensive than using ony one camera.

Jun 17 '12 at 10:22 PM Wolfram

I'm using the camera in my game like this. The relative scales are:

1 - sphere, cube
10 - plane
0.5 - camera (sphere/cube will fill screen at 0.5 orthographic size)
Jun 17 '12 at 11:24 PM Mizuho
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Hm? As the documentation page states, the screen height is just camera.orthographicSize*2 world coordinates, it doesn't get much simpler than that. Also, that's not even relevant, since you can use relative scaling. So store your initial orthographicSize size somewhere, and then scale your HUD with orthographicSize/storedSize.

Note unless you also want to shift positions around (which of course also change), keep all your individual HUD objects in an empty GameObject attached to the camera, make sure it has no local transformations except a z position that's larger than your nearClip value, and only scale this object. All children objects will then seem to stay in place, when changing the size.

more ▼

answered Jun 17 '12 at 10:07 PM

Wolfram gravatar image

Wolfram
9k 8 20 52

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3014
x389
x90

asked: Jun 17 '12 at 09:49 PM

Seen: 1963 times

Last Updated: Jun 17 '12 at 11:24 PM