#### Archived

This topic is now archived and is closed to further replies.

# 3rd person camera troubles

## Recommended Posts

I am developing a game and i want it to be 3rd person, but i am having a big problem. i can get the camera to lock on to the players model but what i really want is, when the camera moves left/right the player also rotates left/right by the same amount.. making it seem like the camera is locked directly behind the player..

##### Share on other sites
Well when getting a press of the left key (for rotating the character left) you''d have to rotate the player model left, but then try to move the camera to the right...i''m not sure about when you start moving forwards and backwards because the origin will stay the same and the character will move...

##### Share on other sites
but how much do i rotate the player by... it seems moving the camera by the same amount of me rotating wont lock the rotation with the camera movements perfectly..

##### Share on other sites

try a polar rotation with the origin where the character is. then refocus the camera to look at the character.

##### Share on other sites
Use gluLookAt....

first 3 parameters are where the camera should be
next 3 are coordinates of what should be in the center of the camera... and the last 3 are which way is up (for most things these are 0,1,0)....

So basically, you know where the character is looking (atleast in terms of angle), so you get the unit direction vector
d=(cos(angle),0,sin(angle) (where angle MUST be in radians)...then you get position of camera using

camera=pos - d*k

where pos is the position vector of your character, and d is the distance you want the camera to be behind the character...

then you call gluLookAt(pos.x,pos.y,pos.z,camera.x,camera.y,camera.z,0,1,0);

all this assuming the terrain is flat...and dont forget to include glu.h

##### Share on other sites
the Look at command is how im doing it and it works perfect al though a little confuseing

• ### Forum Statistics

• Total Topics
628345
• Total Posts
2982191

• 9
• 24
• 10
• 9
• 13