Game Development Community

Help using Path Cam on a spawn point

by Jose M Euvin · in Torque 3D Professional · 03/27/2012 (5:59 am) · 14 replies

I'm new to Torque and I wanted to know if there is a tutorial where I can find how to use path camera. I have two spawn points, and I want my camera to transition from point A to point B using path camera to do a linear smooth transition.

Can anyone point me on the right direction.

Thank you.

#1
03/28/2012 (12:28 am)
I haven't used a path camera in a while but here are some old scripts from TGEA 1.03.

Here are some datablocks:
datablock PathCameraData(Blob1)
{
   mode = "";
   shapeFile = "~/data/shapes/test/blob1.dts";
};

datablock PathCameraData(Blob2)
{
   mode = "";
   shapeFile = "~/data/shapes/test/blob2.dts";
};

Here is the functions that start them off:
function startAllBlobs()
{
   startBlob("blob1","MissionGroup/Paths/Blob1Path");
   startBlob("blob2","MissionGroup/Paths/Blob2Path");
   startBlob("floater","MissionGroup/Paths/Floater1","0.15 0.15 0.15");
   startBlob("floater","MissionGroup/Paths/Floater2","0.15 0.15 0.15");
}
function startBlob(%datablock,%path,%scale)
{
   %blob = new PathCamera() {
      dataBlock = %datablock;
      position = Scene::getStartPos();
   };
   MissionCleanup.add(%blob);
   %blob.reset(0);
   %blob.followPath(%path);

   if (%scale !$= "")
      %blob.setScale(%scale);

   return %blob;
}

And here are the functions that move them around.

datablock PathCameraData(LoopingCam)
{
   mode = "";
};

function PathCameraData::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.getId();
   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);
}

That should give you a good start.
#2
03/28/2012 (3:06 am)
Thank you. One question is why are you using a *.dts file? When creating the datablock do I need to create it with an amimation or is there a way to do bind the current camera to the path camera?

Thank you.
#3
03/28/2012 (9:11 am)
You shouldn't need a shape file. I believe that the option is there simply to allow a visual representation of the camera to appear in the editor.

That said, if you don't assign a shape file you won't see your camera in the editor as far as I know....
#4
03/28/2012 (10:34 am)
I was trying to implement this through the world editor, in it it has a path and nodes objects. Can I create the path and nodes through there and then using scripting implement the rest?


Thank you.
#5
03/28/2012 (4:24 pm)
In theory you use something like:

%camera = new PathCamera();

%camera.pushBack(nodeOne);
%camera.pushBack(nodeTwo);
%camera.pushBack(nodeThree);
%camera.setPosition(0.0); // beginning of path
%camera.setTarget(1.0); // end of path

But in reality I'm not so sure.
#6
03/29/2012 (4:24 am)
function startAllBlobs()  
{  
   startBlob("blob1","MissionGroup/Paths/Blob1Path");  
   startBlob("blob2","MissionGroup/Paths/Blob2Path");  
   startBlob("floater","MissionGroup/Paths/Floater1","0.15 0.15 0.15");  
   startBlob("floater","MissionGroup/Paths/Floater2","0.15 0.15 0.15");  
}

Where exactly are you putting this function and what is a floater?

Why are you referencing to MissionGroup/Path here?
#7
03/29/2012 (5:14 am)
I been programming for 4 years but I feel like I can't rap my head around this thing. This is what I done so far:

This code is in core/art/datablocks/camera.cs where the camera is first created.
datablock PathCameraData(CamPath)
{
   mode = "";
   shapeFile = "art/shapes/vehicles/car/car_body.DAE";
   scale = ".1 .1 .1";
};

datablock PathCameraData(LoopingCam)  
{  
   mode = "";  
};

Then I created a folder to put all the function that I will be passing:

pathCam.cs

function startAllCamPath()  
{  
   startCamPath("CamPath","MissionGroup/Paths/CamPathPath");  
   startCamPath("floater","MissionGroup/Paths/Floater1","0.15 0.15 0.15");  
}  
 function startCamPath(%datablock,%path,%scale)  
 {  
    $CamPath = new PathCamera() {  
       dataBlock = %datablock;  
       position = Scene::getStartPos();  
    };  
    MissionCleanup.add($CamPath);  
    $CamPath.reset(0);  
    $CamPath.followPath(%path);  
   
    if (%scale !$= "")  
       $CamPath.setScale(%scale);  
   
    return $CamPath;  
 }  
 
 function PathCameraData::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.getId();  
   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 in scripts/camera.cs

I tried passing the following funcitons

echo("pushpath");      
      $CamPath.pushPath(node1);
      echo("PathCameraData");
      PathCameraData.onNode($CamPath, node1);

I don't think I'm handling this the right way. I just want to get to a spawn point and have my vehicle drive to a point in the map and then from there the player can star controlling the vehicle.
#8
03/29/2012 (9:28 am)
Quote:
Why are you referencing to MissionGroup/Path here?
That is because you create the Path and markers in the Mission Editor using a specific SimGroup hierarchy. Create a Simgroup, call it Paths. Inside this Simgroup you create the Path Object, give it a specific name that your code will look for. Under this Path Object you create the Markers. Each Marker number will be incremented by one for each one that is placed.

Disregard the extraneous crap about floaters and blobs.

Code should go into the game scripts, not the core. Game scripts may or may not override the default camera scripts found in the core.

Giving a Camera object a shapefile will have no benefit inside the game. You will not see it. Only inside the Editor will it be visible.

Quote:
I just want to get to a spawn point and have my vehicle drive to a point in the map and then from there the player can star controlling the vehicle.
Then that is a bit more complicated than simply using a Pathed Camera. You will need to use a Path (with Markers), enable the AIManager, and have an AI datablock whose shapefile will be a vehicle -- I'm not sure if stock code comes with an AIVehicle, but you can fake it. Once the last marker is reached you will need code to set the player (the Client) as the ControlObject of the Vehicle, from that point the player will be in control.

#9
03/29/2012 (9:55 am)
Michael,

Help me out. I changed the code and I'm reworking the problem and the approach. This is what I done so far.

First:
[code
//This piece of code was added in core/art/datablocks/camera.cs
datablock PathCameraData(CamPath)
{
mode = "";
;
[/code]


Then:
I created pathCam.cs and added the following. I'm also executing it in /scripts/client/init.cs

new SimGroup(Paths)
{
   new Path(CameraPathModel) {
      isLooping = "1";
      canSave = "1";
      canSaveDynamicFields = "1";

      new Marker() {
         seqNum = "1";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Linear";
         position = "-25.0275 -11.5198 1.51868";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         canSave = "1";
         canSaveDynamicFields = "1";
         speed = "5";
      };
      new Marker() {
         seqNum = "2";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Linear";
         position = "-25.0275 -12.5198 1.51868";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         canSave = "1";
         canSaveDynamicFields = "1";
         speed = "5";
      };
      new Marker() {
         seqNum = "3";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Linear";
         position = "-25.0275 -13.5198 1.51868";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         canSave = "1";
         canSaveDynamicFields = "1";
         speed = "5";
      };
      new Marker() {
         seqNum = "4";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Linear";
         position = "-25.0275 -14.5198 1.51868";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         canSave = "1";
         canSaveDynamicFields = "1";
         speed = "5";
      };
   };
};

    
//-------------------------------------------------------------------------------------


$Camera = localclientconnection.camera;

function testPathCamera()  
{  
    %p = createCameraFollowPath(CameraPathModel, CamPath);  
    $savecamera = $Camera;  
    $Camera = %p;  
    LocalClientConnection.setControlObject($Camera);  
    $Camera.setTarget(0);  
}  
  
function cleanTestPathCamera()  
{  
    $Camera.delete();  
    $Camera = $savecamera;  
    localclientconnection.setControlObject($Camera);  
}  
  
function createCameraFollowPath(%path,%name)  
{  
    if( isObject(%path) && %path.getCount())  
    {  
        %pathNode = %path.getObject(0);  
        %transform = %pathNode.getTransform();  
        %pos = getWords( %transform, 0 ,2 );  
        %rot = getWords( %transform, 3 ,6 );  
  
        %p = new PathCamera(myPath) {  
            dataBlock = CamPath;  
            position = %pos;  
            rotation = %rot;  
        };  
          
        for(%i = 1; %i < %path.getCount(); %i++)  
        {  
            %pathNode = %path.getObject(%i);  
            %transform = %pathNode.getTransform();  
            %p.pushBack(%transform,2,"Normal","Spline");  
        }  
          
        return %p;  
    }  
}

When I run testPathCamera() in the console nothing happens. Even after I try using myPath.setTarget(1), 2, 3 etc...

I even try using $Camera.setTarget(1), 2, 3 etc...

myPath.setTarget(0.1), 0.2, 0.3 etc

and $Camera.setTarget(0.1), 0.2, 0.3 etc

Not sure what I'm missing, someone please help.

Thank you.
#10
03/29/2012 (11:34 am)
Are you getting any console errors? I went digging in the source and I didn't see any pushPath() or followPath() methods exposed to the console.

I expected this class to be derived from Camera, but it's not - it comes straight from ShapeBase....

I guess I'll have to check in TGE/A when I get home today and see if there are differences (looks like it, since the script posted is from TGEA). Any ideas Michael?

If you just want a vehicle to follow a path, then mount the player on the vehicle and tell the vehicle to follow the path - you shouldn't need to fiddle with cameras for that. I thought you were trying to set up a cinematic of some sort.
#11
03/29/2012 (11:36 am)
No console errors, its not doing anything. I also tried pushing my own transform and it didn't do anything either.

When I go to close the Torque it crashes.

The way I'm testing my functions is this:

testPathCamera();
      $Camera.setTarget(1);
      $Camera.setTarget(2);
      $Camera.setTarget(3);
      $Camera.setTarget(4);

in the console.
#12
03/29/2012 (3:41 pm)
Technically, target should be from 0.0 (start of path) to 1.0 (end of path), but the source in PathCamera.cc / .h is pretty unclear.
#13
03/30/2012 (3:49 am)
I tried using

testPathCamera();  
   $Camera.setTarget(0.1);  
   $Camera.setTarget(0.2);  
   $Camera.setTarget(0.3);  
   $Camera.setTarget(0.4);

and the camera still not working. Not sure why, I'm not getting any errors in the console, its just not doing anything. Any ideas? Does the code look OK?
#14
04/10/2012 (4:06 am)
See this post for my working version of Path Camera.
www.garagegames.com/community/forums/viewthread/130089