x


changing top down cameras position as such

I'm trying to make a top down shooter, similar to that of the old classics (DoDonPachi, 19xx etc), i've got my movement code, projectile code and camera code, but within the camera code there is a problem, a problem in the sense that the player is not at the bottom of the screen centered, but instead center to the screen, Ive tried to edit code to change this, but no luck, below is my original code, any ideas on what/how to change would be greatly appreciated.

var height = 20.0;
var distance = 0;
var target : Transform;

function Update () {
transform.position = target.position;
       transform.position.y += height;
       transform.position.z -= distance;
       transform.LookAt(target.position);

}

more ▼

asked Jun 25 '11 at 11:28 AM

BobbleHead gravatar image

BobbleHead
189 30 50 67

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

when you use LookAt this will happen and the object that you are looking at will be in center of the screen and using height and distance you can only change viewpoint angles.

you should change the x axis rotation of the camera to 90 (downward) and then put your code without look at. in this way you can find a distance (less than zero) that will do what you want. just remove lookat and rotate camera to look downward (toward ground).

to place a camera in a position that a certain object be in a special position in screen space, you should solve some equations which are not needed here at all.

more ▼

answered Jun 25 '11 at 11:38 AM

Ashkan_gc gravatar image

Ashkan_gc
9.3k 33 56 120

(comments are locked)
10|3000 characters needed characters left
var height = 20.0;
var distance = -1;
var target : Transform;

function Update () {
transform.position = target.position;
       transform.position.y += height;
       transform.position.z -= distance * height;
}

not perfect but this code will do the job for anyone who needs it.

more ▼

answered Jun 25 '11 at 01:47 PM

BobbleHead gravatar image

BobbleHead
189 30 50 67

(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:

x1072
x71

asked: Jun 25 '11 at 11:28 AM

Seen: 581 times

Last Updated: Jun 25 '11 at 01:47 PM