Game Development Community

Altering The Camera to be Top-Down

by Ryan Neighbour · in Torque 3D Professional · 08/26/2009 (4:51 am) · 10 replies

I'm trying to set the camera to be above and behind the player (say 20 feet in the air) and aimed so that the player sits in the middle of the screen about three quarters of the way towards the bottom of the screen (so the centre of the screen is somewhere in front of the player). I'd like to have it track left and right but not up and down with the mouse. I guess this would be pretty similar to the camera set up in Shadow Grounds.

I'm not having much luck and I'm confusing myself more than anything. Anyone have any advice as to where I should start?

Update:
I've locked the vertical look angle by setting minLookAngle (and max-) to 45 degrees. I'm digging around in player.cpp to see if I can have it move up as well as out from the player so I can lock it there too.

P.S. My apologies if I'm slightly incoherent, I really should be asleep right now. :)

About the author

Just started an M.Sc. in Electrical and Computer Engineering during which I'll be investigating the use of Agent Based Models in the field of Epidemiology. Aside from that, trying to get my first indie project off the ground and having a blast doing it.


#1
08/26/2009 (6:12 am)
Update:

After a bit of mucking about I got almost exactly what I was looking for.

img21.imageshack.us/img21/8273/w00q.jpg
The only problem is it's partially hardcoded:

I made a change in player.cpp
void Player::getCameraParameters(F32 *min,F32* max,Point3F* off,MatrixF* rot) {
...
//10 from 0
off->set(0.0f, 0.0f, 10.0f); 
...
}

I'd like to make it so that I can change the values of the offset from script, but it's late and I'm pretty bagged.

Once I figure out how to make that script modifiable I'll have to figure out how to ensure that the PC always fires forward and not into the ground right in front of it.

Comments and suggestions are more than welcome.

Oh, before I forget...

If I maximize the window, the boombot moves almost all the way off screen. Can someone explain that one to me? Is it that the view is res dependent?

Off to bed,

Cheers!
#2
08/26/2009 (6:26 am)
If i remember right you can gain control of the camera cia script or make a new camera and control that one.
#3
08/26/2009 (7:11 am)
@Kevin: I definitely have to figure out the scripting side. I'm pretty lost on that side of things.

I managed to get the camera to do more or less what I want it to but I have an issue: When the camera rotates it doesn't stay where I want it to: ie: 10 units above, and 3 units behind the player.

Instead, it moves where I tell it to, then stays in formation with the player (in world space). It rotates the way it's supposed to, it just does it a few meters let's say west of the player. It keeps the right vertical distance above the player (when going up or down hill) but it just doesn't stay behind the player.

edit:
This is using
off->set(0.0f, 3.0f, 10.0f);

in the function above

#4
08/26/2009 (7:39 am)
With very few changes (aka: disable the collision with other players) you can use a Camera object in OrbitMode to do the same thing. You have much better control of the rotation, distance and view angle.
#5
08/26/2009 (8:50 pm)
@Manoel: Honestly when it comes to scripting I'm a little more than lost. I'd much rather do this in script than hard code it for more than a few obvious reasons but I can't seem to find where the camera is set to go into the default mode so I'm not sure about changing it.

I did see something about orbit mode in the source but last night I was pretty burned out.

By the way, you were referring to doing that in script right?
#6
08/27/2009 (9:34 pm)
The GameConnection owns the camera and the player.

\game\scripts\server\game.cs

onClientEnterGame - This is where the camera and player are created for the connection. This calls spawnCamera and spawnPlayer.

\game\core\scripts\server\spawn.cs

spawnCamera - this creates the camera for the connection. pickCameraSpawnPoint() is used to create a dummy default sphere if a spawn sphere group for cameras does not exist.

spawnPlayer - this creates the player from either the class/datablock on the spawn sphere or the defaults. It then looks for a camera and if it finds one sets the transform of the camera to the players eye or just the objects transform.

I believe this is where the camera for the player is ultimately setup. You could set the mode and transform here in script.

I'm not sure the impact of the setFirstPerson thing has on the use of the camera though.

Not sure if this is ideal, someone can correct me if there's a better place. Maybe messing with the defaultcamera stuff.
#7
08/28/2009 (10:17 am)
I tried mucking about in spawnPlayer but I can't seem to get anything to happen regarding the camera.

I set a break point at the beginning of the function and stepped through pretty much everything (and I do mean everything, 500 F11's later and...) using Torsion but all that seemed to do was make the world editor open...
#8
08/28/2009 (10:38 am)
Somewhere close to where the player is created a camera is created as well, which is used when you press alt+C. You need to switch it to orbit mode (call setOrbitMode() on it - do a search for it, since the death code uses it as well) and make it the client's camera object (.setCameraObject() on the client object).
#9
08/28/2009 (11:35 am)
Huzzah! It was because I wasn't calling setCameraObject.

Now I just need to get it to track with the player. Right now it's just floating level with the player and doesn't track rotation. But at least I'm closer.

Thanks for the help guys :)
#10
08/28/2009 (12:35 pm)
K, I have a question.

If I want the camera to be above, slightly behind, and looking down at the player and to have the camera track rotation about the z axis only, should I even use the orbit mode? Or should I just translate and rotate the camera?