x


Camera Stays in the Center

Hi,

Currently, I have a camera set to follow the hero in a 2d game. The current camera focuses on the hero and stays in the center of the screen, but I would like the camera to follow the hero but stay at the bottom of the screen. How would I do that? I have a very simple camera script.

Here is a snippet:

function Update (){
    transform.eulerAngles = Vector3(0,0,0);
}

How do I accomplish my goal? Other than the above script, the camera values are the default settings.

Thank you for your assistance.

more ▼

asked Apr 29 '12 at 02:53 AM

Dr_GeoFry gravatar image

Dr_GeoFry
84 9 20 23

Could you clarify what you mean by having the camera "at the bottom of the screen"? The camera essentially "is" the screen, so it's a little unclear as to what you're attempting to do.

Apr 29 '12 at 05:55 AM dwsarber

So, within the frame, I want the hero to stand on his platform on the bottom of the frame. Right now, the hero stands on the platform which is in the center of the frame. Does that make sense?

Apr 29 '12 at 06:06 AM Dr_GeoFry

Ahh, yes, that helps a great deal. One further question: Is the camera a child object of your Hero in the scene hierarchy?

Apr 29 '12 at 06:12 AM dwsarber

Yes, the camera is a child of the hero. It is connected to the hero via an empty gameObject. So it is Hero>>GameObject>>Camera.

Apr 29 '12 at 06:22 AM Dr_GeoFry
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

If I'm understanding your question and comments correctly, then it seems all you need to do is set the Y position of the camera to some positive value. Assuming the camera object doesn't have a rotation other than the default, setting it to a larger Y position will make the Hero appear where you want in the Viewport (in this case at the bottom). Since the camera is a child of the Hero, it will continue to automatically follow him around, even with this new position.

more ▼

answered Apr 29 '12 at 07:06 AM

dwsarber gravatar image

dwsarber
52 1 2

Are you saying to increase the value of the Y in the Normalized View Port? I can't set it any higher than like 1.0 and I'm not seeing any difference. As for like the y-axis of the camera, that doesn't make sense to me since it will rotate the camera...

Apr 29 '12 at 05:36 PM Dr_GeoFry

Additionally, can one camera follow two gameObjects?

Apr 29 '12 at 05:50 PM Dr_GeoFry

@ the first comment, you want to increase the Y Position value in the Transform component of the camera. It will move it "up" relative to its parent object. The only way it rotates is if you change the Rotation values in the Transform, or its parent object rotates (in the same way).

@ the second comment, each camera will only ever be looking at one object or in one direction at a time. It could be possible to have two objects/directions be the focus, but the camera would have flip back and forth between them.

Apr 29 '12 at 06:52 PM dwsarber

Thanks, man. Very helpful.

Apr 29 '12 at 07:20 PM Dr_GeoFry
(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:

x2994
x80

asked: Apr 29 '12 at 02:53 AM

Seen: 402 times

Last Updated: Apr 29 '12 at 08:47 PM