Overhead 2d ChaseCamera using physics

Nov 7, 2007 at 8:59 PM
I'm thinking about adding a chase camera (2D) that simply follows an object along (like in so many 3-D 3rd person games). I figure that I'll have an invisible object attached to the object I'm chasing using a linear spring. Then I'll just get the position from the invisible object and have my camera match it.

The catch is that I am doing an overhead game and I would like for the invisible object to also orient its "facement" toward the chased object. That way, I can grab that rotation and have the camera gravitate to viewing the chased-object as facing the top of the screen.

Are there any physics components (or combinations of) that would allow me to do this naturally? (sorry if this is obvious)

If not, I suppose that I could just gradually interpolate toward the vector from the invisible object to chased object.

Nov 7, 2007 at 11:54 PM
I don't understand why you need physics for a camera.
Nov 8, 2007 at 12:30 AM
You typically use spring physics for a camera to give a more cinematic, less jarring, effect. Instead of having the camera ridgedly fixed on the target, it is allowed more freedom to move more naturally...
Nov 8, 2007 at 5:31 AM
That sounds more like something you would want to code yourself.
Nov 9, 2007 at 12:09 PM
A spring would probably be a bad choice, since your camera would wobble quite a bit. You probably want a camera that has an offset that gets translated towards a target offset (the player's position) by a certain percentage every frame, or just use XNA's vector interpolation methods.
Nov 19, 2007 at 5:36 PM
Could you use an AngleSpring as well?
Jun 1, 2009 at 11:19 PM

I really enjoy using the physics engine for the camera, it just requires a lot of playing to get the right effect.

Jun 2, 2009 at 3:34 AM

Have you taken a look at this? I believe it interpolates to the target properties at a pre-defined rate, so you could just set the Position, Rotation, Zoom... etc properties as they change in your game.

Jun 2, 2009 at 4:23 AM

@sterling you are correct

that camera uses vector2.lerp to follow the given body at speed you set,

its simple to use, just declare the camera

initialize it

give it a tracking body

update it

then pass the camera.cameramatrix into the spritebatch

thats it in a nutshell

Jun 2, 2009 at 5:32 AM

What TLegion said, plus you can write your own Update method (for camera control). Its set up for a GamePad right now but it can be easily adapted to a keyboard or mouse :). I'll be updating it soon to use Lambdas for camera control, so that you can define your own update method on the fly!

Jun 2, 2009 at 1:19 PM

this is off-topic. but is farseer written in .net 3.5, or just .net 3.0

i have wondered bofore when writing patches.

the projects i looked at where set to .NET 3.0 but i wasn't sure if that was just a coincidence

Jun 2, 2009 at 3:04 PM

Farseer Physics Engine 2.1 is target for .net 3.0

The next version will be targeting .net 3.5 - For now at least, this might change if any compatebility issues arrise (thinking Xbox 360 and compact framework)