PathShape
by Stefan Beffy Moises · 12/08/2003 (8:52 am) · 61 comments
Download Code File
**********************************************************
* A modified PathCamera object that enables you to move
* static shapes (DTS files) along (camera) paths
* This will only work in Release 1.2 or HEAD since it is based on
* the new PathCamera stuff!!!
**********************************************************
Here is how to add a pathed shape to your game:
Add the .cc and .h file to engine/game, add them to your project and recompile the engine...
copy pathShape.cs to your "example/demo/server/scripts/" folder e.g.
and exec it in "game.cs" as usually...
then add the path to your shape in that file:
You can add a PathShape like this from script e.g.:
**********************************************************
* A modified PathCamera object that enables you to move
* static shapes (DTS files) along (camera) paths
* This will only work in Release 1.2 or HEAD since it is based on
* the new PathCamera stuff!!!
**********************************************************
Here is how to add a pathed shape to your game:
Add the .cc and .h file to engine/game, add them to your project and recompile the engine...
copy pathShape.cs to your "example/demo/server/scripts/" folder e.g.
and exec it in "game.cs" as usually...
then add the path to your shape in that file:
datablock PathShapeData(LoopingShape)
{
emap = true;
// put path to your shape here!!
shapefile = "~/data/shapes/foo/bar.dts";
mode = "";
};You can add a PathShape like this from script e.g.:
// --> beffy: create pathed shape start ! :)
%pathshape = new PathShape() {
dataBlock = LoopingShape;
// set position to whatever suits your needs...
position = "102.46 155.34 98.22";
};
// give it a path to follow:
%pathshape.followPath("MissionGroup/Scenes/TerrainEngineScene/Path");
// cleanup
MissionCleanup.add( %pathshape );
// <-- beffy: create pathed shape end ! :)
#22
02/02/2006 (11:24 am)
Has anyone set it up to so you can start an object on a random nod in the path or on any nod other then the first one?
#23
@Josiah & all: I've changed the scripts so that
a) I resolved the bit overflow when adding a complete path with lots of nodes (over 50 didn't work since there was too much data send over the network, see the extended PathManager resource by eXodus)
b) it's possible to start from any node in the path
Note that in my script you have to first call e.g.
now to start from any other node than 0, change $currentNode to any number you like...
of course, you have to set the initial position and rotation of the shape accordingly :)
Here's the complete script:
02/03/2006 (1:27 am)
@Tim: glad you like it :)@Josiah & all: I've changed the scripts so that
a) I resolved the bit overflow when adding a complete path with lots of nodes (over 50 didn't work since there was too much data send over the network, see the extended PathManager resource by eXodus)
b) it's possible to start from any node in the path
Note that in my script you have to first call e.g.
%myShape.setPath("MissionGroup/Paths/Path1");and then %myShape.startfollowingPath();The trick to overcome problem a) is to simply NOT add the complete path at any given time, but instead add a bunch of nodes each time, so that you always stay below the nodeWindow amount defined in pathShape.h... adding chunks of 8 nodes and setting nodeWindow in pathShape.h to 15 worked best for me...
now to start from any other node than 0, change $currentNode to any number you like...
of course, you have to set the initial position and rotation of the shape accordingly :)
Here's the complete script:
//********************************************
// Looping path shape
//********************************************
$isFollowingPath = false;
$currentNode = 0;
$counter = -1;
$nodeWindow = 8; // max. 15, see pathShape.h
datablock PathShapeData(LoopingShape)
{
emap = true;
// put path to your shape here!!
shapefile = "~/data/shapes/african/african.dts";
mode = "";
};
function LoopingShape::onAdd(%this,%obj)
{
// do whatever you want with that shape, e.g. play animations:
//%obj.playThread(0,"rota");
}
function LoopingShape::onNode(%this,%theshape,%node)
{
$counter++;
if(%theshape.path.isLooping && (%node == %theshape.loopNode))
{
$currentNode = 0;
$counter = -1;
echo("At end of path, setting position back to starting node.");
%theshape.followPath();
}
else
{
%theshape.pushNextNodes();
}
}
function PathShape::pushNextNodes(%this)
{
%atEnd = false;
// we only want to add nodes if we are just starting,
// finishing a loop or need the next chunk of nodes
if(($counter < 0) || ($counter == ($nodeWindow - 1)))
{
%start = $currentNode;
%end = %start + $nodeWindow;
if(%end >= %this.path.getCount())
{
%end = %this.path.getCount();
%atEnd = true;
}
for(%i=%start;%i<%end;%i++)
{
error("PUSHING NODE:" SPC %i);
%this.pushNode(%this.path.getObject(%i));
// set next node offset
$currentNode = %i + 1;
}
if(%atEnd)
%this.pushNode(%this.path.getObject(0));
$counter = 0;
}
}
// stop pathfollowing
function PathShape::stopfollowingPath(%this)
{
%this.setState("stop");
}
// start pathfollowing
function PathShape::startfollowingPath(%this)
{
%this.setState("forward");
if(!$isFollowingPath)
{
%this.followPath();
$isFollowingPath = true;
}
}
function PathShape::setPath(%this,%path)
{
echo("PathShape::setPath(" @ %this @ "," SPC %path @")");
%this.path = %path;
if (!(%this.speed = %path.speed))
%this.speed = 10;
if (%path.isLooping)
{
// substract $currentNode in case we are not starting from the first node!
%this.loopNode = %path.getCount() - $currentNode;
}
else
{
%this.loopNode = -1;
}
}
function PathShape::followPath(%this)
{
%this.reset(%this.path.speed);
%this.pushNextNodes();
}
function PathShape::pushNode(%this,%node)
{
if (!(%speed = %node.speed))
%speed = %this.speed;
if ((%type = %node.type) $= "")
%type = "Normal";
if ((%smoothing = %node.smoothing) $= "")
%smoothing = "Spline"; //Linear / Spline
%this.pushBack(%node.getTransform(),%speed,%type,%smoothing);
}
#24
02/03/2006 (10:00 am)
Awesome, thanks I will give it a try :)
#25
02/15/2006 (3:36 pm)
I would like to reiterate a question posed here. I too have tried it and it works great but I would like to have a camera attached to the object that can be controlled by the player. Any help would be greatly appreciated. Thanks !
#26
02/21/2006 (10:17 am)
Hey ! great resource but I am creating the object when I enter the game and the problem is that I would like to name the new when it is created. I used the %obj.setName("UAV") but it still is created with out this object name. Any help would be greatly appreciated. Thanks !
#27
Randy
04/23/2006 (10:24 pm)
Works great! Thank you for the resource. I have a ship with TLK lights mounted to it that follows the path. Looks awesome. What is the common approach to getting these shapes to rotate on the fly ( turn my spaceship around ). I can't seem to get the setTarget() working and there is no setRotation(). I could animate my .dts I suppose. Randy
#28
05/10/2006 (8:41 pm)
Any ideas if this will work with 1.4
#29
05/11/2006 (5:25 am)
I am using 1.4 TLK and it works well.
#30
05/11/2006 (7:55 am)
Did you have to do a lot of mods to get it to work?
#31
05/11/2006 (6:01 pm)
None at all. Just make sure you put in the Edward F. Maurina III (Mar 17, 2004 at 01:49) changes. These allow the shape to loop around the nodes.
#32
05/22/2006 (2:23 am)
useful.. i'm gonna try this.
#33
05/22/2006 (5:54 pm)
Is there any way to offset the position of the object on the path dynamically? I want to be able to move the mouse to the left (reflected by the $mvYaw variable), and have the object move to the left of the path , but still follow the curve, but follow it at an offset. Is this even possible?
#34
tw
05/24/2006 (4:37 pm)
pathShape works very well, but I need to put too many paths in the mission file. Is it possible to call a path from the mission file and then dynamically change the position of the nodes? If not, then Justin's offset question would also help my problem.tw
#35
Paths - SimGroup
Path1 - Paths
marker
I know the datablock is correct because the object show in the treeview.
05/31/2006 (9:00 am)
I try this resource today. I have no console error but my shape just sit there. I know I am problem missing something simple. Do I need to put a dynamic field to point to the path name. I sat up my paths like thisPaths - SimGroup
Path1 - Paths
marker
I know the datablock is correct because the object show in the treeview.
#36
06/09/2006 (5:34 pm)
Anyone have any ideas on how to get the pathshape to update the marker locations? I'm modifying my paths in real time, but the pathshape follows the old marker locations and not the modified ones.
#37
::edit::
My mistake, i didn't follow the direction properly :p
06/22/2006 (6:47 pm)
The Player isn't able to "step up" onto a pathshape object. I'm looking thru the code now to add support for this. Anyone already know how to add this in?::edit::
My mistake, i didn't follow the direction properly :p
#38
thank u for this resource it is more usefull for me, but i got a error that path cannot be found, but i specified a path and camera is moving along the path, what is the problem in my script,
08/03/2006 (8:27 pm)
hi thank u for this resource it is more usefull for me, but i got a error that path cannot be found, but i specified a path and camera is moving along the path, what is the problem in my script,
#39
Did you ever get the shape to support a player for lifts, etc ?
I can mount the player to the lift but walking around would be more fun.
10/05/2006 (7:30 pm)
Thanx@Edward ! Did you ever get the shape to support a player for lifts, etc ?
I can mount the player to the lift but walking around would be more fun.
#40
I did infact get some support for this.
10/06/2006 (2:42 pm)
www.garagegames.com/mg/forums/result.thread.php?qt=47074I did infact get some support for this.

Torque Owner Tim Heldna
Excellent resource, i love it!!! So many different uses for this, endless posibilities. Thanks for sharing.
P.S.
Thanks to Edward & Ash for their helpful contributions as well.