Game Development Community

Pathed Camera Help

by Tim Heldna · in Torque Game Engine · 02/03/2006 (6:29 am) · 5 replies

Hi everyboody,

Needing a little help with a minor problem.

I have my game set up so you first spawn in as a camera (in observer mode) & can look around the level controlling that camera. You have to press a key to bring up a gui that allows you to select player/team etc.

What i want to do is create my own camera datablock that follows a path resulting in a fly thru of the mission (very similar to the torque demo's).

I know how to make a path etc and have got the pathShape resource in as a guide but i just can't seem to work this out for camera's. I know of the old resource regarding pathed cameras but don't want to put this in for two reasons:

1) It won't compile
2) I'm pretty sure this function is already in standard Torque head code

Can someone give me some assistance please?

I'm guessing the basic steps would be:

1) Create a path
2) Create a camera datablock similar to the observer datablock in server/scripts/camera.cs
3) Within this datablock (or within a function deriving from this datablock) set the camera to my path
4) In game.cs within the 'onClientEnterGame' function set it to spawn as my newly made path following camera

Any ideas or suggestions greatly appreciated...

#1
02/03/2006 (7:08 am)
Ok, nevermind i worked it out. I feel like an idiot cos i was doing it right all along apart from one little '%this' that i was leaving out.

If anyone else want's to know how to do this let me know & i'll post the code here.
#2
02/03/2006 (7:49 am)
@Tim,
post it - Please.
#3
02/03/2006 (8:11 am)
Ok, create a new script (i called mine cameraPreview.cs) and place it in the server/scripts directory. Open up game.cs & execute this newly made script. Here's what to put inside the 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);
}

Will continue in new post in case i run out of room in this one...
#4
02/03/2006 (8:14 am)
In server/scripts game.cs change your entire function GameConnection::onClientEnterGame(%this) function to look like 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);
}
#5
02/03/2006 (8:19 am)
Lastly make a path within your mission file (as you can see mine's called MissionPreviewPath) and you're done.

When the mission loads in you will spawn as a camera that flys around the path you set for it. I won't go into it too much more cos if you read through the scripts it's all pretty self explanitory.

N.B. I have put in the team selection resource which binds a key to bring up a gui to allow you to spawn in as a player. You will need a similar setup otherwise you'll be stuck as a camera!

Hope this help, enjoy!!!

Let me know if you have any problems

-Frank Skilton