Game Development Community

3rd person camera system - request for comments/help

by Thomas \"Man of Ice\" Lund · in Torque Game Engine · 03/20/2004 (7:13 am) · 12 replies

Hey,

For my game project I'm in need of a non-controlable 3rd person camera. My camera needs to be a little more sophisticated than the current 3rd person camera system in some places, and I would like to hear if anyone wants to offer their help or comment on my ideas.

I am also unsure where to add this code. I've tried looking at GameConnection, Camera and the Player classes, and it could go anywhere in there. Maybe it would be better to create a new class for this.... Anyone with input on this?

The goal is to release this as a general resource for all to use afterwards.

My thoughts and ideas are as follows. Please comment if you got input or ideas

* Damped movement of the camera.
Imagine the camera on a rubber band dragging after the player. I think a spring is perfect for this, and we have Hookes law for springs saying F = -k*x (k is the spring constant and x the displacement) and damping F = -b*v (b is the damping coefficient and v the velocity). Combining then we get F = -k*x - b*v. Using the deltaTime between ticks it should be fairly easy to calculate the displacement during the tick and then modifying the position of the camera.

* Camera aligning itself with the terrain
When the player moves up/down on terrain the camera should not stay horizontal, but follow the terrain, so its z axis is perpendicular to the terrain. This makes it easier to see where you are going as a player. Having never looked at the terrain code I'm quite unsure how to access this information and use it. I hope its possible to query the terrain code with a position to get the normal vector, and then use that to rotate the camera up/down.

* Locking the camera movement axis
When moving inside buildings or interiors it would sometimes be a good thing to lock the camera in its movement axis. I could envision that you could lock the x,y axis, so the cam can only move in z so it doesnt bounce into the walls and stays behind the player in narrow areas. This could be done with triggers in both ends of a narrow tunnel.


Are there any other features you could add to this?
Are my ideas crazy?
Better ways of doing things?
Do you have existing code that you want to contribute?
Should I create a new camera class or extend existing functionality?

Lets make a great 3rd person cam resource for all to use by combining forces. I dont imagine this to be more than a few days work, but I might as well try to see if anyone else is in need of this and make a more generally usable camera than just for my own needs (which will probably not be usable for anyone but me)

#1
03/20/2004 (3:26 pm)
I'd make a ThirdPersonCamera class and use that. Add some scriptable methods like "trackObject" and such.

The first idea sounds good. Especially the dampening equation, which I must remember to use in the future.

Second idea is also good. I suggest using getHeightAndNormal, which is a method off of TerrainBlock, as I recall.

The triggered camera behavior is good. I'd suggest making it be triggered when you're INSIDE a trigger, not with start/end triggers, as that way you don't have to worry about the user somehow missing an exit and getting stuck in a weird camera mode forever.
#2
03/20/2004 (8:04 pm)
What 3rd person battle camera, that keeps you and a target in veiw. It should act like your first idea, but be able to follow 2 objects.
#3
03/21/2004 (12:51 am)
Good one Josh.

I think that would be a nice one too. Should be easy to do. One just has to set the "object to observe" to the targeted player, and keep the spring system attached to the controlled object.
#4
03/23/2004 (3:38 pm)
Camera aligning itself with the terrain - do a raycast from player position - some distance on the z vector, masked for terrrain objects only. You will get the normal you want. You may have to smooth it or something though, and if the player is going to do anything akin to flying around, you have to think if you want it to stop aligning, etc.

For locking the movement axis - it sounds more like the intent is to force it to point down either the positive or negative of a vector (say, either direction in the tunnel). Here's a simple idea I got, it might be crazy, but thats up to you to decide. It would make turning around really annoying since you couldnt see backwards.

Diagram (these are triggers):
______________________________
| | | |
| A | B | C |
|______|______________|______|

B includes A & C

when you enter A or C it tells the camera to snap to a vector that points down the direction you want. While inside of B, the camera sticks to that vector and wont rotate to look where the play is looking, etc.

Would this do something like what you are talking about? Like I said, you couldnt look backwards if this was done. It may be better to have it zoom in behind your shoulder or something.

(btw Man of Ice, this is TalonHawk if the name rings a bell)
#5
03/23/2004 (5:36 pm)
I think he's going for a Zelda OoT style camera.
#6
03/24/2004 (12:20 am)
Hey TalonHawk! How are ya?

Yeh - you got a point. Some restricted movement would be nice though. Maybe its enough to add collision detection to the camera, so it doesnt jump into the walls or makes the player disappear. Thats the reason for even thinking about locking the camera down
#7
03/27/2004 (1:17 pm)
A little status. After a day of hacking the existing TrackingCamera resource, I've managed to implement a 3rd person camera. The code can now switch between tracking and 3rd person with a script method.

The placement of the camera is scriptable as an offset from the object you observe.

It will be fairly trivial (I hope) to add the spring system to that camera.

There are various problems at the moment. The offset is (at the moment) in world coordinates, and I need to work in local coordinates for the player. Else the camera will always face in the same world direction. There is also a problem with interpolating the position when the player moves. The camera jitters around in steps.

More news soon, and hopefully a resource when this is done.

(The code is in a separate class and very easy to add/use. One only needs to hack the gameconnection class as specified in the "camera object" resource)
#8
07/28/2005 (9:35 pm)
Thomas,

I know this is kinda an old thread but I was wondering if you ever got the rubber (spring) effect done with the camera. I am finding I need the same thing with my camera. If not, is there anything you can point me to as working with matrix/vectors is not my strongest point.

Thanks

PS: I am already using your great AdvancedCamera resource.
#9
07/29/2005 (1:35 am)
Hi Simon,

No - I never got around to implement it. My need for it disappeared (due to cancelling the adventure title I was working on).

The physics are very simple. Damped spring - try to look it up on google and you get tons of hits.

Then add a new mode to adv cam - should be fairly easy to implement.
#10
05/03/2008 (6:34 pm)
Was the resource for this ever made i require a third person over the shoulder style camera such as in Gears of War or Resident Evil 4
#11
06/07/2008 (5:31 am)
"Was the resource for this ever made i require a third person over the shoulder style camera such as in Gears of War or Resident Evil 4"

I'm wondering about this also. Any information on how to get this done?
#12
06/07/2008 (9:53 am)
There are several resources that should be able to do this, you should try the Advanced Camera or the Game Camera resources. If you own AFX, the camera that come with it is easily modified to apply the Damped Spring effect.