Archived

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

Trying to create a third person camera...

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

If you intended to correct an error in the post then please contact us.

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;
	adj = abs(tankGreen.fPosX - midX);
	hyp = abs(tankGreen.fPosZ - midZ);
	theta = ((acos(adj / hyp)) * 2);
	direction += theta;
}
  
Any help would be appreciated, thanks.
Fa||en_Ange| Productions

Share this post


Link to post
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

Share this post


Link to post
Share on other sites