#### Archived

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

# Trying to create a third person camera...

This topic is 5817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey there, I''ve been having some trouble lately trying to implement a third person camera for my current game. At the moment I''m using the tutorial from gametutorials.com, and I have a camera set up fine which follows my object (a tank) and rotates around it fine. However what I''m trying to do now is make the tank rotate with the camera so that it is always facing straight ahead. I''ve managed to get it to partially work, however when the rotation angle hits 45 degrees, the whole thing falls apart for me. Here''s the code that I''m using for this:

if ((key == ''A'') || (key == ''a'')) //Turn left.

{
float oldX, oldZ, newX, newZ, midX, midZ, adj, hyp, theta;
oldX = camera.m_vPos.x;
oldZ = camera.m_vPos.z;
printf("oldX: %f oldZ: %f\n", oldX, oldZ);
camera.rotateAroundPoint(camera.m_vView, 0.03, 0, 1, 0);
newX = camera.m_vPos.x;
newZ = camera.m_vPos.z;
midX = (oldX + newX) / 2;
midZ = (oldZ + newZ) / 2;
midX *= 10;
midZ *= 10;
hyp = abs(tankGreen.fPosZ - midZ);
theta = ((acos(adj / hyp)) * 2);
direction += theta;
}

Any help would be appreciated, thanks.
Fa||en_Ange| Productions

##### Share on other sites
if you want to have a camera that can encircle an object look into polar coordinates...

As for cameras, also read up on quaternion maths...

however to position a camera behind something facing in the same direction that the object is pointing, why not just set the direction vector for your camera to be the same as the direction vector for the object, set the position the same, and then move it back n units against the direction vector...? And then you can always translate it verticly...

i dunno, i''ve never had to do this, there could be a better way.

hope this helps

-jonnii

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631759
• Total Posts
3002138
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!