Sign in to follow this  
Kazade

Advanced 3rd Person Camera

Recommended Posts

Hi, I am writing a small 3d sonic the hedgehog game. I've written a 3rd person camera class, but i want it to act like the one in the official sonic games. In sonic heroes (SA2, SA1 etc.) the camera does not exactly follow the player, but allows the player to run around in its view, but it rotates to follow the track of the level. This is kinda hard to explain... In this image you can see what i mean, the camera views the direction of the level but it is not behind sonic. Does anyone know how this is achieved, im assuming some kind of stored camera path? I thought perhaps it follows a curve through waypoints, but the camera does move side to side slightly too. It isnt totally fixed on a curved path. Anyone have any ideas on how i can recreate this in my game? Cheers Luke.

Share this post


Link to post
Share on other sites
i havent played the game so im guessing, perhaps u wanna smooth the camera movement out? check flipcode from a few years ago, see one of the ask midnight column's, where camera movement is based on the average over a few frames

Share this post


Link to post
Share on other sites
The 3rd person camera is best implemented with quaternions and spherical linear interpolation (slerping). This creates smooth rotation transitions and it's easy to hook the camera up to the player on-screen (in this case, Sonic), or give control to the user.

Share this post


Link to post
Share on other sites
I could give you some tips on smoothing the movement of your camera, but I think your issue is higher level. Okay, so I assume you know that player motion is relative to the camera's orientation to the player... when you press forward on the joystick, the player runs in the direction the camera is facing to the player.

So your question is actually two competing ones: 1) What happens when I want the camera to face a certain direction and 2) How do I let the user control the camera at the same time?

I encourage you to very thoroughly examine the Jak & Daxter camera, it's really the highest quality, most flexible camera system in many cases. In their case, when they use the camera to point you forward in the level they take away user control while the camera rotates into position, then put it completely back in user control once they've pointed out the objective. There are other modes where they'll lock the camera's orientation to a perspective relative to the viewer, or they'll pivot the camera around a point in the distance and focus on the player.

They key is: when you want to unexpectedly change the orientation of the camera, do it very quickly and all at once. Because the semantic direction of what pressing 'forward' means (the direction the player expects to move) changes with the orientation of the camera, it is very bad to change it unnecessarily or unexpectedly (though sometimes it is necessary).

Share this post


Link to post
Share on other sites
Hi. Can't you update the position of the camera to the position of the character just a few pixels out and up. You could use something like:

_pcamera = new CCamera;
_pcamera->SetPosition(_this->_psonic->Getx()+10, _this->_psonic->Gety()+10, _this->_psonic->Getz()+10);

maybe that would work?

Share this post


Link to post
Share on other sites
Thanks for the replies, but i think you all misunderstand me (except perhaps ajas95). I already have a 3rd person camera, thats not a problem, my camera follows behind the player. What i need is a way for the camera to stay focused on the player, but the position of the camera does not necessarily follow the player. I believe I can achieve what I want by making the camera position follow a series of control points through the level, i just need to work out the maths now :)

Anyone have any decent links on bezier curves? More specifically finding the closest point on a curve to another point.

Cheers

Luke.

Share this post


Link to post
Share on other sites
bezier curves whilst easy dont go through the control points, myself i bsplines as they go through the control points
paul bourkes site has good mathmatical stuff

http://astronomy.swin.edu.au/%7Epbourke/index.html

Share this post


Link to post
Share on other sites
man, I think this can be done in many ways. One of them, apply direction of object to direction of camera, put camera back from object with reverse direction and add some 'up' value ... (z for example)

Share this post


Link to post
Share on other sites
Sorry, its hard to explain. I've worked out some of it myself. So now all i need to do is work out how to make a camera follow a curved path through a map. But it needs to be able to move back and forward along this path based on the position of the players character.

I need to find the point on a curve nearest to the position of a player.

Hope that helps,

Luke.

P.S. Cheers Zedzeek that helps a lot.

Share this post


Link to post
Share on other sites
Ah well, That's easy. Find the nearest point on the curve, and if you cache from frame to frame the current position on the curve, then it should be cheap. Then use LERP to smooth it out.

To find the closest point on a curve, well, usually, I don't bother with perfect curves, and use a segmented approximation. Then it's only a matter of finding the segment the closest to where you want it to be, which is easy code (point to segment distance).

here is an example.

Share this post


Link to post
Share on other sites
I think you are misleading yourself by thinking you need to define a spline. What I think you want to do is done frequently in the Two Towers and ROTK games, and there are generally 2 modes:

1) Just pick some orientation and distance that the camera should sit relative to the player (in world space). As the player runs around, the camera keeps the same orientation and distance with hopefully some nice smooth damped motion.

2) Pick some pivot point off in the distance, and wherever the player runs, keep the camera locked in line with the player and the pivot point. This makes the camera always trained on some "important" spot no matter where the player goes. Again, nice smooth motion is a good idea.

Another thing you can do is to not have the player be in the dead center of the screen, and instead have the camera look slightly in whichever direction the player is facing. Presumably, the player is facing the action, so it's an aid to the camera to have more of what the player is interested in on the screen.

Another tricky part is transitioning between 2 different camera modes. You need to make it happen quickly but not be too jerky. This can be very difficult. I feel I should emphasize that smooth motion is important :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this