Modifying the camera
by __._ · in Torque Game Engine · 10/09/2006 (1:52 am) · 9 replies
Good day to all,
I am wondering how I can alter the camera through script. I've been going through just about every file from the tutorial.base but can't seem to locate where the camera is created and attached to an object (the player). Basically I want to learn how to make different camera types, 3rd person in particular, but also a camera that is stationary and still tracks the player (keeps looking at it). Where do I go?
Thanks in advance.
I am wondering how I can alter the camera through script. I've been going through just about every file from the tutorial.base but can't seem to locate where the camera is created and attached to an object (the player). Basically I want to learn how to make different camera types, 3rd person in particular, but also a camera that is stationary and still tracks the player (keeps looking at it). Where do I go?
Thanks in advance.
#2
10/10/2006 (2:36 am)
ALready read that. Unfortunately I can't use it. I need to use Torque "out of the box". Any other suggestions?
#3
10/10/2006 (2:46 am)
You will find it difficult (if not impossible) to make such major changes in script. Script is mostly for gameplay stuff, not engine core.
#4
I found some code in the starter.fps scripts, that is responsible for placing the camera above the player, having an eagle-eye view of the world. However I don't really understand how to make it work. It lists this code:
and when the player dies, it reads:
My testproject doesn't have any onDeath trigger, therefore I tried making this code execute right away, like so:
10/10/2006 (2:51 am)
Well isn't the camera a part of the gameplay? ;) I know it has 3rd person support already. I guess it's possible to change the distance through script, but haven't found out how yet. Where could I find an overview of variables for the camera? I found some code in the starter.fps scripts, that is responsible for placing the camera above the player, having an eagle-eye view of the world. However I don't really understand how to make it work. It lists this code:
function Observer::setMode(%this,%obj,%mode,%arg1,%arg2,%arg3)
{
switch$ (%mode)
{
case "Observer":
// Let the player fly around
%obj.setFlyMode();
case "Corpse":
// Lock the camera down in orbit around the corpse,
// which should be arg1
%transform = %arg1.getTransform();
%obj.setOrbitMode(%arg1, %transform, 0.5, 4.5, 4.5);
}
%obj.mode = %mode;
}
//-----------------------------------------------------------------------------
// Camera methods
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function Camera::onAdd(%this,%obj)
{
// Default start mode
%this.setMode(%this.mode);
}
function Camera::setMode(%this,%mode,%arg1,%arg2,%arg3)
{
// Punt this one over to our datablock
%this.getDatablock().setMode(%this,%mode,%arg1,%arg2,%arg3);
}and when the player dies, it reads:
%this.camera.setMode("Corpse",%this.player);My testproject doesn't have any onDeath trigger, therefore I tried making this code execute right away, like so:
function GameConnection::onClientEnterGame(%this)
{
// Every client get's a camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
%this.camera.setMode("Corpse",%this.player); // <- this is the only new line
// Create a player object.
%spawnPoint = pickSpawnPoint();
%this.createPlayer(%spawnPoint);
}hoping it would set up the camera to an eagle-eye view right away. Unfortunately it does absolutely nothing, and I just get lost in all the parameters the functions need. How can I accomplish this? Or where do I read about it?
#5
What you've outlined is the observer camera. That's the camera that's used when you hit Ctrl-c to fly around. It's not going to be able to give you an eagle eye view of things.
Tom had a good suggestion: Check out the Advanced Camera resource.
It is a great resource put together by a few different GG community members that has multiple camera modes, one called a "God View" mode (like eagle eye) that may be what you are looking for.
Once you add that resource in, you will be able to make different kinds of calls from script to change camera modes and settings, etc.
10/13/2006 (12:28 pm)
Hi RJ,What you've outlined is the observer camera. That's the camera that's used when you hit Ctrl-c to fly around. It's not going to be able to give you an eagle eye view of things.
Tom had a good suggestion: Check out the Advanced Camera resource.
It is a great resource put together by a few different GG community members that has multiple camera modes, one called a "God View" mode (like eagle eye) that may be what you are looking for.
Once you add that resource in, you will be able to make different kinds of calls from script to change camera modes and settings, etc.
#6
10/13/2006 (1:14 pm)
The advanced camera resource was created for this very purpose.
#7
10/14/2006 (10:25 am)
I know and I do appreciate the suggestions. But I was told not to modify the source of the engine. I am currently learning Torque myself so it can be used for educational purposes next schoolyear, but one specific instruction is to use Torque out of the box, so without adding code and recompiling. The FPS demo game has a camera that zooms out a bit when you kill yourself, so it must be possible somehow.
#8
But then it has been a while since I have looked (and have never specifically looked at the death instance and what is exposed).
A better idea if you cannot change the engine is to change the third person reference on the model when you create your 3D artwork. Or design your levels with camera pathing in mind and update the camera during gameplay along the paths. But that is extremely complicated in comparison to the AC resource for an orbit cam.
10/14/2006 (11:13 am)
I believe that came from C++ extensions for that specific explicit functionality which was then exposed to the scripting engine (just like the Advanced Camera extends it even more). Chunks of the AC resource are in the C++ source, but I do not believe they have been exposed to the scripting engine.But then it has been a while since I have looked (and have never specifically looked at the death instance and what is exposed).
A better idea if you cannot change the engine is to change the third person reference on the model when you create your 3D artwork. Or design your levels with camera pathing in mind and update the camera during gameplay along the paths. But that is extremely complicated in comparison to the AC resource for an orbit cam.
#9
10/18/2006 (5:14 am)
That might actually do it :) Haven't gotten that far yet, but after reading the last bits of the manual, my understanding of it is that I can just put a marker in 3D max which automatically becomes the camera's eye, therefore I can place the camera as far away from the model as I want? Not sure it's possible AT ALL, but maybe that would allow for a "fake" player just for the camera (therefore invisible), and the real player model as a separate object that's updates as well when you move the "fake" player.
Torque 3D Owner Tom Perry