How to use PathCamera?
by Nicolas Tian · in Torque Game Engine · 06/06/2005 (1:19 am) · 8 replies
Sorry I'm a absolute newbie, I just tried to use PathCamera, but it didn't work, can anyone tell me why?
Here is my pathCamera.cs (I modified it from pathShape.cs):
Then I modified the function onClientEnterGame:
When I ran the demo, nothing happened! Can anybody help me with this? I really appreciate your help! Thanks a lot!
Here is my pathCamera.cs (I modified it from pathShape.cs):
datablock PathCameraData( MyPathCamera )
{
mode = "";
};
function MyPathCamera::onAdd(%this, %obj)
{
}
function MyPathCamera::onNode(%this, %camera, %node)
{
}
function PathCamera::followPath(%this, %path)
{
%this.path = %path;
if (!(%this.speed = %path.speed))
%this.speed = 100;
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);
}Then I modified the function onClientEnterGame:
function GameConnection::onClientEnterGame(%this)
{
// Every client get's a camera object.
%this.camera = new PathCamera()
{
dataBlock = MyPathCamera;
};
%this.camera.followPath("MissionGroup/CameraPath");
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Create a player object.
%spawnPoint = pickSpawnPoint();
%this.createPlayer(%spawnPoint);
}When I ran the demo, nothing happened! Can anybody help me with this? I really appreciate your help! Thanks a lot!
#2
I just modified the function GameConnection::onClientEnterGame as you suggested, but it still didn't work - nothing happened.
Are there any wrongs with my pathCamera.cs?
Please help!
06/06/2005 (2:11 am)
Gonzo, thanks a lot!I just modified the function GameConnection::onClientEnterGame as you suggested, but it still didn't work - nothing happened.
Are there any wrongs with my pathCamera.cs?
Please help!
#4
Gonzo, thanks again! Have you tested to use PathCamera in your demo?
Or can anyone else give me a help? Thanks a lot!
06/06/2005 (3:23 am)
I just took the line out of "followPath", still no luck - nothing happened.Gonzo, thanks again! Have you tested to use PathCamera in your demo?
Or can anyone else give me a help? Thanks a lot!
#6
- get the base tutorial package from http://www.codesampler.com/torque.htm
- in the directory tutorial.base/server create a file pathCamera.cs with this code
This is actually taken directly from the Torque Demo (at the bottom of scene.cs)
- create a path in the editor or copy this path into your mission file
- in line 26 of server/game.cs insert this line
exec("./pathCamera.cs");
- also in game.cs, add this at the bottom of the GameConnection::createPlayer method:
Now you have a looping camera! Unfortunately, you'll never get player control, so you might want to add the two schedules below. There might be an easier way for that.
If you set the isLooping in the path to '0' you'll get a nice 'Intro Cam', because the camera circles once, then comes to stop, until the engine switches to player perspective and control.
10/15/2005 (3:21 am)
Since I was interested in that, too, I tried this from a clean code base. Here is one way to do it.- get the base tutorial package from http://www.codesampler.com/torque.htm
- in the directory tutorial.base/server create a file pathCamera.cs with this code
//-----------------------------------------------------------------------------
// 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 = 100;
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);
}This is actually taken directly from the Torque Demo (at the bottom of scene.cs)
- create a path in the editor or copy this path into your mission file
new SimGroup(Paths) {
new Path(Path1) {
isLooping = "1";
new Marker() {
position = "128.506 -610.857 207.436";
rotation = "1 0 0 0";
scale = "1 1 1";
seqNum = "3";
type = "Normal";
speed ="50";
smoothingType = "Spline";
};
new Marker() {
position = "19.2114 -414.944 214.947";
rotation = "1 0 0 50";
scale = "1 1 1";
seqNum = "2";
type = "Normal";
speed ="60";
smoothingType = "Spline";
};
new Marker() {
position = "23.5063 -430.857 166.036";
rotation = "1 0 0 30";
scale = "1 1 1";
seqNum = "1";
type = "Normal";
speed ="30";
smoothingType = "Spline";
};
};
};- in line 26 of server/game.cs insert this line
exec("./pathCamera.cs");
- also in game.cs, add this at the bottom of the GameConnection::createPlayer method:
%this.pathCamera = new PathCamera() {
dataBlock = LoopingCam;
};
%this.pathCamera.followPath( "MissionGroup/Paths/Path1");
MissionCleanup.add( %this.pathCamera );
%this.setControlObject(%this.pathCamera);Now you have a looping camera! Unfortunately, you'll never get player control, so you might want to add the two schedules below. There might be an easier way for that.
If you set the isLooping in the path to '0' you'll get a nice 'Intro Cam', because the camera circles once, then comes to stop, until the engine switches to player perspective and control.
%this.pathCamera = new PathCamera() {
dataBlock = LoopingCam;
};
%this.pathCamera.followPath( "MissionGroup/Paths/Path1");
%this.schedule(6500, "MissionCleanup.add", %this.player);
%this.schedule(7000, "setControlObject", %this.player);
MissionCleanup.add( %this.pathCamera );
%this.setControlObject(%this.pathCamera);[EDIT] changed object name from camera to pathCamera, otherwise it is in conflict with the original camera.
#7
12/30/2005 (7:00 am)
Any way to use it changing speed at any time?
#8
I've been trying to use this feature in my game but im getting some issues...
The code that Dirk "dirkk" Krause wrote works just fine, but if I want to use the pathcamera for a cutscene activated by a trigger event it doesnt work!
I have tried a lot of scripting trying to fix this but with no sucess. My last attempt was to add a new function at the bottom of the (server) game.cs :
this is the error I get on the torsion console :
could someone explain me what Im doing wrong here? Sorry about my newbness, but my brain cells got burned with this one...
THKX!
07/03/2007 (12:32 pm)
Hi everyone!I've been trying to use this feature in my game but im getting some issues...
The code that Dirk "dirkk" Krause wrote works just fine, but if I want to use the pathcamera for a cutscene activated by a trigger event it doesnt work!
I have tried a lot of scripting trying to fix this but with no sucess. My last attempt was to add a new function at the bottom of the (server) game.cs :
...
function CSTrigger::onEnterTrigger(%this)
{
%this.pathCamera.followPath( "MissionGroup/cutscene01");
%this.schedule(6500, "MissionCleanup.add", %this.player);
%this.schedule(7000, "setControlObject", %this.player);
MissionCleanup.add( %this.pathCamera );
%this.setControlObject(%this.pathCamera);
} which is basically the same code on the GameConnection::createPlayer method.this is the error I get on the torsion console :
... starter.fps/server/scripts/game.cs (395): Unable to find object: '' attempting to call function 'followPath' Set::add: Object "" doesn't exist starter.fps/server/scripts/game.cs (402): Unknown command setControlObject. Object CSTrigger(25) CSTrigger -> TriggerData -> GameBaseData -> SimDataBlock -> SimObject ...
could someone explain me what Im doing wrong here? Sorry about my newbness, but my brain cells got burned with this one...
THKX!
Torque Owner Gonzo T. Clown
function GameConnection::onClientEnterGame(%this) { // Every client get's a camera object. %this.camera = new PathCamera() { dataBlock = MyPathCamera; }; %this.camera.followPath("MissionGroup/CameraPath"); MissionCleanup.add( %this.camera ); %this.setControlObject(%this.camera); }