Game Development Community

dev|Pro Game Development Curriculum

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:
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 ! :)
#42
12/14/2006 (8:48 pm)
Hai Ramen

I tried to get into that link.Since i am a TSE owner i was not able to get it.
I too want the player to set on to the pathshape.
Any help
#43
12/14/2006 (11:40 pm)
@roshan
E-mail me, i'll email you the files i modified. Perhaps it will be of use.
#44
12/18/2006 (12:20 am)
Hai Ramen

Got your resource and it working fine in TSE.
Porting ur code in TSE is not a big deal.Any how if u want it pls let me know.

THANKS A LOT!!!!!!!!!!!!!!!!
#45
07/23/2007 (11:54 am)
Using TGE 1.5.2, I am having two problems. (A) After Ash's collision implementation, no collision is occurring (note that this collision is with a flyingVehicle and not a player). (B) The PathShape loses its geometry (or at least disappears) after a short period of time.

Any possible solutions? Thanks.
#46
07/27/2007 (4:50 am)
How would you go about adding a path to an already existing object? I tried to make it easy for me and simply add a pre-existing datablock instead of LoopingShape to a new PathShape but this only resulted in the cryptic error message: "Object '393' is not a member of the 'GameBaseData' data block class", which I really have no idea what it means.
#47
07/30/2007 (5:19 am)
@Chad: besides Ash's changes above, you also need a castRay() implementation for the PathShape... e.g. copy it over from player.cc:
bool PathShape::castRay(const Point3F &start, const Point3F &end, RayInfo* info)
{

   // Collide against bounding box. Need at least this for the editor.
   F32 st,et,fst = 0,fet = 1;
   F32 *bmin = &mObjBox.min.x;
   F32 *bmax = &mObjBox.max.x;
   F32 const *si = &start.x;
   F32 const *ei = &end.x;

   for (int i = 0; i < 3; i++) {
      if (*si < *ei) {
         if (*si > *bmax || *ei < *bmin)
            return false;
         F32 di = *ei - *si;
         st = (*si < *bmin)? (*bmin - *si) / di: 0;
         et = (*ei > *bmax)? (*bmax - *si) / di: 1;
      }
      else {
         if (*ei > *bmax || *si < *bmin)
            return false;
         F32 di = *ei - *si;
         st = (*si > *bmax)? (*bmax - *si) / di: 0;
         et = (*ei < *bmin)? (*bmin - *si) / di: 1;
      }
      if (st > fst) fst = st;
      if (et < fet) fet = et;
      if (fet < fst)
         return false;
      bmin++; bmax++;
      si++; ei++;
   }

   info->normal = start - end;
   info->normal.normalizeSafe();
   getTransform().mulV( info->normal );

   info->t = fst;
   info->object = this;
   info->point.interpolate(start,end,fst);
   info->material = 0;
   return true;
}
No idea why the shape would disappear though...

@Matthias: I have no idea what you are talking about, sorry...
#48
07/31/2007 (1:57 am)
@Stefan: No worries, I hardly have any idea myself :) Or more to the point, I had not looked through the code very thoroughly when writing the last post. The problem I guess, is that we've done quite a rewrite of shapeBase here and that is the reason why something breaks. So I'm probably on my own in figuring out how to get this rolling.
#49
07/31/2007 (7:59 am)
Is there anyway that I could mount/attach an ParticleEmitter to a PathShape object? If so, how?
#50
08/01/2007 (1:41 am)
@Chad: I don't know about mounting but as for my problem (above) the solution was to copy-paste code from pathShape to my custom shapeBase class, in effect making it a pathShape object. This should probably work for particleEmitter to.
#51
08/01/2007 (1:53 am)
I now have another problem here. My unit is animating along the spline path but the movement around the nodes ain't very smooth, see video for an example. http://skickafilen.se/downloadnow.jsp;jsessionid=EFA6F274EF942F3270E7CF282B691807 How do you insert a link here by the way?

So I'm wondering how you go about "straightening out" the curve to avoid these twitches that occur on every node.
#52
08/13/2007 (1:11 pm)
@Matthias: that link doesn't work...
#53
01/03/2008 (8:43 am)
Hi, I'm trying to add this resource as some kind of a movable obstacle that can hit a player. When I tried it and placed the player at the Path Shape's path, it passes through and doesn't trigger collision at all. How can I fix this and can call the player's onCollision()?

BTW, thanks a lot for the resource. A great one indeed.

EDIT: I also need the shape to toggle a trigger. But it seems like it can't do that also.
#54
01/08/2008 (1:14 am)
Anyone figure out how to get shadows working with the pathshape?

::edit::

alright, i figured it out. was rather simple
#55
02/15/2008 (5:53 am)
@Maurina, could you also share your engine source code modifications? I just found the scripts changes.

Thanks
#56
02/15/2008 (10:46 am)
@Gustavo,

Hi. Any code changes I made are listed above.

Please note. This resource is a little old, so some code may not match exactly.

Also note, if you are looking for rideable moving platforms you might try this instead: HERE.

Hall Of Worlds - For Gamers
EdM|GPGT
pictures and plan describing the resource
#57
02/15/2008 (11:07 am)
@Edward,

Just noticed that, its all there. Thank you very much.
#58
05/23/2008 (11:05 am)
is this working for 1.5.2?
#59
09/23/2008 (9:23 am)
Hi

Just to let people know I added support for pathShape to set off triggers, but I did my post over here

www.garagegames.com/mg/forums/result.thread.php?qt=29206#556782

Hope it comes in helpful,

Cheers Ramen and all you other guys. You've saved me a serious amount of time :)

Tom
#60
02/12/2009 (8:21 am)
could you upload the latest pathshape files for TGEA 1.7.2.. Thanks