# Third Person Camera Psuedocode

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

## Recommended Posts

I'm testing around with gluLookAt() and WM_MOUSEMOVE to develop a third-person shooter camera. I'm working on the psuedocode right now and here's what I have: When the camera moves, back up the old x,y mouse coordinate and record the new x,y mouse coordinate. Calculate the average change by subtracting the old x&y coordinate by the new one and dividing by two. Store the average variable in a different x&y coordinate. Calculate the new position of the camera using the averaged x&y coordinate The section that's bolded is the portion I need help with; I don't know how to get the camera to move in a circle around the character. The third person camera will be a usual one, move the mouse up and down and you aim up and down, move it left to right - so on and so forth. Can someone help me develop the psuedocode for the equation of the camera position? Centering the camera on the person won't be a problem since gluLookAt() already takes care of that problem.

##### Share on other sites
Store the camera as a horizontal angle (unbounded), a vertical angle (locked between 90 and -90 degrees), and a distance from a look at point (probably the hero's head). A change in the mouse x coord should add or subtract from the horizontal angle, and a change in y should change the vertical angle. From there it is just trig to find the actual camera location. You may have to play with negating either or both of the deltas in order to influence your angles in the correct directions.

// scale the change according to a// sensitivity that feels good,// then add to our anglesax += mouse_delta_x * mouse_sensitivity_scalar;ay += mouse_delta_y * mouse_sensitivity_scalar;// lock ay so that camera doesn't turn upside downif (ay > 90) ay = 90;if (ay < -90) ay = -90;// find the point on the unit spherepos.y = sin(ay);pos.x = cos(ay) * sin(ax);pos.z = cos(ay) * cos(ax);// increase the radius as desiredpos *= dist;// center around the lookat pointpos += lookat;

##### Share on other sites
I have some bugs to work through, but other than that it works, thanks. :)

1. 1
2. 2
Rutin
23
3. 3
4. 4
frob
16
5. 5

• 9
• 33
• 13
• 12
• 10
• ### Forum Statistics

• Total Topics
632579
• Total Posts
3007168

×