Pathed Camera
by Tim Heldna · 02/28/2006 (6:58 pm) · 22 comments
I wanted to create a mission preview of my level before the player spawns in. A pathed camera immediately came to mind (like the ones in the torque demo). I had a look around but couldn't find much useful information on the subject.
There was one old resource which i dismissed as it seemed dated and required head code changes (I avoid any head code changes if it can be done in script), so after working out how to do this I thought I'd share...
1). Create a new *.cs script file called pathCamera.cs (or whatever you like) and place it in the server/scripts directory.
2). Execute this script from within server/scripts/game.cs in the usual manner i.e. exec("./pathCamera.cs");
3). Here's what to put in this new script...
5). Now all you have to do is create a path within your mission (mine's called MissionPreviewPath as you can see) and you're set. Inside pathCamera.cs if you look inside the function PathCamera::followPath(%this,%path) section you'll also notice you can change the speed of your camera.
6). So to give you an example; To have it so you spawn into a mission as a camera that loops around your mission on a path, replace your whole function GameConnection::onClientEnterGame(%this) function inside server/scripts/game.cs with this...
That's it. If you don't know how to create a path check out the stronghold mission and look at the path kork uses.
If you don't know how to get it to spawn as a player check out this resource on team selection. It covers a lot of useful ground.
Teams Implementation
Enjoy, let me know if you have any problems.
There was one old resource which i dismissed as it seemed dated and required head code changes (I avoid any head code changes if it can be done in script), so after working out how to do this I thought I'd share...
1). Create a new *.cs script file called pathCamera.cs (or whatever you like) and place it in the server/scripts directory.
2). Execute this script from within server/scripts/game.cs in the usual manner i.e. exec("./pathCamera.cs");
3). Here's what to put in this new script...
//-----------------------------------------------------------------------------
// Path Camera
//-----------------------------------------------------------------------------
datablock PathCameraData(LoopingCam)
{
mode = "";
};
function LoopingCam::onNode(%this,%camera,%node)
{
if (%node == %camera.loopNode) {
%camera.pushPath(%camera.path);
%camera.loopNode += %camera.path.getCount();
}
}
function PathCamera::followPath(%this,%path)
{
%this.path = %path;
if (!(%this.speed = %path.speed))
%this.speed = 10;
if (%path.isLooping)
%this.loopNode = %path.getCount() - 2;
else
%this.loopNode = -1;
%this.pushPath(%path);
%this.popFront();
}
function PathCamera::pushPath(%this,%path)
{
for (%i = 0; %i < %path.getCount(); %i++)
%this.pushNode(%path.getObject(%i));
}
function PathCamera::pushNode(%this,%node)
{
if (!(%speed = %node.speed))
%speed = %this.speed;
if ((%type = %node.type) $= "")
%type = "Normal";
if ((%smoothing = %node.smoothing) $= "")
%smoothing = "Linear";
%this.pushBack(%node.getTransform(),%speed,%type,%smoothing);
}4). There are several different ways of adding this camera into your game. This is the script you'll need... (don't worry an example will follow if you're new to torque)// Create path camera
%this.PathCamera = new PathCamera() {
dataBlock = LoopingCam;
position = "0 0 300 1 0 0 0";
};
%this.PathCamera.followPath("MissionGroup/Paths/MissionPreviewPath");
MissionCleanup.add( %this.PathCamera);
%this.PathCamera.scopeToClient(%this);5). Now all you have to do is create a path within your mission (mine's called MissionPreviewPath as you can see) and you're set. Inside pathCamera.cs if you look inside the function PathCamera::followPath(%this,%path) section you'll also notice you can change the speed of your camera.
6). So to give you an example; To have it so you spawn into a mission as a camera that loops around your mission on a path, replace your whole function GameConnection::onClientEnterGame(%this) function inside server/scripts/game.cs with this...
function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
// Create a new camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Create path camera
%this.PathCamera = new PathCamera() {
dataBlock = LoopingCam;
position = "0 0 300 1 0 0 0";
};
%this.PathCamera.followPath("MissionGroup/Paths/MissionPreviewPath");
MissionCleanup.add( %this.PathCamera);
%this.PathCamera.scopeToClient(%this);
$Server::Client = %this;
%this.setControlObject(%this.PathCamera);
}7). You'll obviously want to create another similar function that spawns you in as a player when you're ready.That's it. If you don't know how to create a path check out the stronghold mission and look at the path kork uses.
If you don't know how to get it to spawn as a player check out this resource on team selection. It covers a lot of useful ground.
Teams Implementation
Enjoy, let me know if you have any problems.
About the author
Recent Blogs
• BCS Street props• Character Pack - Vince
• Recent Artwork
• Progress of our Weapon Pack
• Digital Speedometer
#22
06/21/2010 (12:55 am)
Why does camera is controlled on server? Shouldn't it be a client-side feature? Why do we need to waste bandwidth for it? 
Associate Dave Calabrese
Cerulean Games
Make your 'PathCamera::followPath' function look like this:
function PathCamera::followPath(%this,%path,%doNoReset) { %this.path = %path; if (!(%this.speed = %path.speed)) %this.speed = 10; if (%path.isLooping) %this.loopNode = %path.getCount() - 2; else %this.loopNode = -1; if(!%doNoReset) { %this.setState(stop); %this.reset(); } %this.pushPath(%path); %this.popFront(); }Enjoy!
-Dave Calabrese
Gaslight Studios
edit: added a 'do not reset' command for the times that you want it to blend between paths.