Camera relative character movment/Circling

Started by
2 comments, last by Kyall 12 years, 3 months ago
Hi,

I'm trying to implement a camera-character movement similar to Mario and Zelda, where your camera tracks the character when they move left or right, but moves forward and backwards with character motion.
The problem I'm having is if I keep the character moving left or right, the character doesn't exactly keep a perfect circle. It would eventually spiral away from the camera. I am applying a velocity to my character along the x-axis of the current camera axis (camera relative x-axis). This seems like instability similar to using euler equations to do numerical integration.

Anyway, can someone give me pointers on how I can fix this or get a similar treatment like how Mario or Zelda do their character-camera system? I just want my character to move in a circle while the camera is tracking it.

Thanks.
Advertisement
I'm not quite understanding your problem, but I'll try and help anyway.

1. Calculate the inverse of your view matrix from the previous frame, use a vector to represent the value of input, multiply the input vector by the inverse of the view matrix, you now have a world space transform that gives you the input based on the view
2. Target the camera at the players position, always except with overrides for aiming, lookabout
3. Set a maximum radius that the camera must stay within relative to the player.
4. Get the distance between the player and the camera
5. Get the direction from the camera to the player, so the vector difference divided by distance
6. Simple way: Move the camera using a formula that takes distance, direction, time into account

camerapos += direction * ( distance - maximum ) * H * DT
where:
H is a scalar to tweak the translation of the camera
DT is the difference in time from the last fram


7. Another method however is to use that equation to move the camera, but to clamp the camera to an outer radius that it can never move beyond, so peform equaiton 6 then the following for this:

Get the direction and distance from the camera to the player
if the distance is more than the outer range, use the following formula

camerapos = playerpos - direction * outerrangedist


That should pretty much do it for you, with some tweaking. But all that does is give you a camera that looks at the player, to look beyond the player you can use some similiar blending for the camera target.

EDIT:

OH woops, you don't use the inverse of the entire view matrix ( a 4x4 with translation and rotation ) you use the rotation part only (3x3, first 3 columns first 3 rows ) and you get the inverse of that rotation and use that. Sorry about any confusion.
I say Code! You say Build! Code! Build! Code! Build! Can I get a woop-woop? Woop! Woop!
My camera is looking at the player.
I calculate the inverse of the camera matrix and multiply that by my input vector to get world space movement vector.
My input vector is to move right.
The player moves right relative to the camera.
My camera's new look at position is the new player's position.
I don't want to move the position of my camera because the player is only moving right. The camera should theoretically just be rotating.

If the input is kept moving right, the camera position shouldn't be moving at all, just rotating in a circle and the player is also moving in a circle. Right?

If you look at the movement from Mario or Zelda, you can make them move in a circle just by holding left/right on the analog stick. The camera doesn't move.

In your equations, you are moving the camera position to maintain the radius, thus the camera does not stay stationary.
Am I understanding this correctly?

My camera is looking at the player.
I calculate the inverse of the camera matrix and multiply that by my input vector to get world space movement vector.
My input vector is to move right.
The player moves right relative to the camera.
My camera's new look at position is the new player's position.
I don't want to move the position of my camera because the player is only moving right. The camera should theoretically just be rotating.

If the input is kept moving right, the camera position shouldn't be moving at all, just rotating in a circle and the player is also moving in a circle. Right?

If you look at the movement from Mario or Zelda, you can make them move in a circle just by holding left/right on the analog stick. The camera doesn't move.

In your equations, you are moving the camera position to maintain the radius, thus the camera does not stay stationary.
Am I understanding this correctly?


Pretty much, but if the character is close to the camera and you just hit right you'll probably run around in a circle.
I say Code! You say Build! Code! Build! Code! Build! Can I get a woop-woop? Woop! Woop!

This topic is closed to new replies.

Advertisement