Stationary camera with target
by James Jacoby · in Torque Game Engine · 01/04/2004 (11:15 am) · 8 replies
Would I have to make any changes to the code to implement a stationary camera that tracks a target. For example:
I want to script portions of my game so that when the character enters a tight space, the camera switches from orbit to a fixed location in the room (i.e. the top of the room). However, I want the camera to still point at the character as they move around the room.
Any ideas?
I want to script portions of my game so that when the character enters a tight space, the camera switches from orbit to a fixed location in the room (i.e. the top of the room). However, I want the camera to still point at the character as they move around the room.
Any ideas?
About the author
#2
in camera.cc, add:
of course, camera.h:
The following server functions set the control to the cam (or back to the player) and the first one lets you point the camera from/to any position you set it to:
01/04/2004 (11:53 am)
Here are some quick pointers:in camera.cc, add:
ConsoleMethod( Camera, lookAt, void, 4, 4, "")
{
Point3F dir, pos, lookAtPos;
Camera *camObj = (Camera *) object;
camObj->setControlDirty();
dSscanf(argv[2],"%f %f %f",
&pos.x,&pos.y,&pos.z);
dSscanf(argv[3],"%f %f %f",
&lookAtPos.x,&lookAtPos.y,&lookAtPos.z);
camObj->lookAt(dir, pos, lookAtPos);
}
void Camera::lookAt(Point3F &dir, const Point3F &pos, const Point3F &lookAtPos)
{
Point3F vec = lookAtPos - pos;
F32 yawAng, pitchAng;
MatrixF m = MathUtils::createOrientFromDir(vec);
m.setColumn(3,pos);
setTransform(m);
}of course, camera.h:
void lookAt(Point3F &dir, const Point3F &pos, const Point3F &lookAtPos);
The following server functions set the control to the cam (or back to the player) and the first one lets you point the camera from/to any position you set it to:
function serverCmdSetCameraTarget(%client)
{
// set 2 positions
%newCamPos = "100 100 100";
%targetPoint = %client.player.getTransform();
%client.camera.lookAt(%newCamPos, %targetPoint);
%client.setControlObject(%client.camera);
}
function serverCmdSetControlToPlayer(%client)
{
%client.setControlObject(%client.player);
}hope this helps a bit...
#3
Thanks!
01/04/2004 (5:10 pm)
I'll give that a try. However, I don't fully understand the SetControlObject method. Does that make it so the input (keyboard/mouse) are controlling that object? If so, how would you control the player once the camera is targeting? Is there a list of all the built in scripting functions and their descriptions?Thanks!
#4
EDIT: Thanks for the code; that got me going in the right direction. Seems to work fine without that setControlDirty command. However, you lose control of the player since control is switched to the camera. Also, this command does not update each frame; making it impossible to 'track' the player. Looks like a more serious code edit is in order :)
I seem to remember a tutorial someone wrote regarding advanced camera movement. I'll see if I can adapt that code to this code somehow. I'll post it if I get it working.
01/04/2004 (8:54 pm)
I cannot find the method setControlDirty() defined anywhere in the source so I'm going to comment that line out and try it anyway. What is the purpose of that line? EDIT: Thanks for the code; that got me going in the right direction. Seems to work fine without that setControlDirty command. However, you lose control of the player since control is switched to the camera. Also, this command does not update each frame; making it impossible to 'track' the player. Looks like a more serious code edit is in order :)
I seem to remember a tutorial someone wrote regarding advanced camera movement. I'll see if I can adapt that code to this code somehow. I'll post it if I get it working.
#5
Glad it got you started :)
But you are right, its probably not what you want as you loose control of the player... the "advanced camera" would really be better (although it wont work in HEAD anymore I think, you gotta fix that...), or look for "god view" in the resources, that could be useful, too ...
Also look for "setOrbitMode" in the camera class/script and play around with that, maybe you could use that as a start, too...
01/04/2004 (10:26 pm)
Yeah, as I said, just some pointers, it wasn't meant as "plug & play" ;-)Glad it got you started :)
But you are right, its probably not what you want as you loose control of the player... the "advanced camera" would really be better (although it wont work in HEAD anymore I think, you gotta fix that...), or look for "god view" in the resources, that could be useful, too ...
Also look for "setOrbitMode" in the camera class/script and play around with that, maybe you could use that as a start, too...
#6
Can you give a few pointers on what changed in HEAD that broke it?
Or explain quickly WHERE the hell the position of the 3rd person camera is stored??? ;)
I understood that the 'camera' is indeed class Camera, und the normal 1st person camera is NOT a camera. The 3rd person isnt either a camera I guess!? The 1st and 3rd person use the getCameraTransformation functions to hook to some Shape...?
Damn, this is a mess. ;)
You got a pointer to the docs that I should read? I didnt really find the right ones.
01/10/2004 (6:32 pm)
Stefan, that advanced camera code doesnt work anymore for some reason, as you said. I am just a newbie currently with Torque, so I wasnt able to make it work.Can you give a few pointers on what changed in HEAD that broke it?
Or explain quickly WHERE the hell the position of the 3rd person camera is stored??? ;)
I understood that the 'camera' is indeed class Camera, und the normal 1st person camera is NOT a camera. The 3rd person isnt either a camera I guess!? The 1st and 3rd person use the getCameraTransformation functions to hook to some Shape...?
Damn, this is a mess. ;)
You got a pointer to the docs that I should read? I didnt really find the right ones.
#7
Try this one, exactly what you need.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4720
01/10/2004 (10:36 pm)
James,Try this one, exactly what you need.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4720
#8
01/10/2004 (10:42 pm)
Oupss, didn't looked at the date. Ralf's fault :) You already found it.
Torque 3D Owner Frogger