Game Development Community

Camera on path

by Nathan · in Technical Issues · 08/22/2005 (11:19 am) · 10 replies

Hi, could sombody tell me how to create a camera that fallows a path, like the one in the Torque Game Engine demo?
Thanks,
Nathan

#1
08/22/2005 (12:41 pm)
The code is actually right there - in the TGE demo. Start in the server side game.cs and work your way through it. Also check the paths in the mission editor

With just a little tinkering you will have it running within an hour tops
#2
08/22/2005 (12:49 pm)
If he's using the free download, does he have the source? I gather he's using the free version if he's posting on these forums.

- Brett
#3
08/22/2005 (12:57 pm)
He has the script files with an excellent example of how to put a camera on a path.
#4
08/22/2005 (1:23 pm)
Thanks for the replies! I actually have looked in the TGE demo, but was unable to get it to work in my game. I've been trying to get this to work for about 4 hours, and it's still not working, so any more help would be greatly appreciated.
#5
08/22/2005 (1:30 pm)
Nathan - look in the root folder for console.log.

It should provide some insight into what's not working properly and, following the error reports, point you to what scripts might need adjusting.
#6
08/22/2005 (1:32 pm)
Try this.
#7
08/22/2005 (1:39 pm)
George - he's not an SDK owner... will he be able to access that page?
#8
08/22/2005 (1:42 pm)
@Kirby - I'll try that.

@George - I think that only works if you own Torque, and I don't :(
#9
08/22/2005 (3:13 pm)
Kirby -I read console.txt (if that's what you meant), and I didn't find any errors.

This is the code I'm using now:

function GameConnection::onClientEnterGame(%this)
{
   // Create a new camera object.
   %this.camera = new Camera() 
   {
      dataBlock = Observer;
   };

   MissionCleanup.add( %this.camera );
   %this.camera.scopeToClient(%this);
   
   // Create path camera
   %this.player = new PathCamera() 
   {
      dataBlock = LoopingCam;
   };

   MissionCleanup.add( %this.player );
   %this.player.scopeToClient(%this);

   // Start up the room gui system
   $Server::Client = %this;
   %this.setControlObject(%this.player); 
}


//-----------------------------------------------------------------------------
// Scene Class
//-----------------------------------------------------------------------------


// Scene activation is driven from the DemoGui and related scripts.
// (see demo/client/scripts/demoGui.cs)

function Scene::open(%this)
{
   echo("Scene " @ %this.getName() @ " open");
   %client = $Server::Client;
      
   // Set the path to follow, the camera will start at
   // the first node in the path.
   %path = %this.getId() @ "/path";
   if (isObject(%path)) {
      %client.player.reset(0);
      %client.player.followPath(%path);
   }
   else {
      // Check for a static camera
      %start = %this.getId() @ "/start";
      if (isObject(%start)) {
         echo("Static Camera");
         %client.player.reset(0);
         %client.player.pushNode(%start);
         %client.player.popFront();
      }
   }
}


//-----------------------------------------------------------------------------
// 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);
}
#10
08/22/2005 (5:00 pm)
Does anybody know what I'm doing wrong? I'm new to Torque and don't have a clue how to script cameras.