Game Development Community

Object moving along path

by Frank Bignone · 09/20/2002 (9:48 am) · 28 comments

Download Code File

The following code adds support for :
- object moving along path
- spline or linear path
- one way or cyclic path
- path triggering : start / stop / change path
- animation triggering : start / stop

The path code works only with a new object named DynamicShape, but it's easy to put it in another gamebase class. The code is based on the latest HEAD revision of Torque.

The archive file should be uncompress in your torque folder. It will modify the following file in the engine :
- shapebase.h
- mathutils.cc & mathutils.h
- pathManager.cc & pathManager.h
- simPath.cc & simPath.h

and these ones in the example folder :
- AIEButtonBarDlg.gui, Editor.cs & objectBuilderGui.gui
- waterworld.mis
- game.cs

You should add the file dynShape.cc in your makefile / vc project and recompile the torque example.

The following script functions may then be used :
- cleanPathMission() : remove all dynamic object (should be run once).
- addPathDynamicObject( objName, DTSfilename, PathName ) : add an object moving along the path named PathName and with the DTSfileName as 3D models. It returns an handler to the dynamic shape created. The path may have the attribute type which means : 0-2 : linear or spline one way path, 1-3 : linear or spline cyclic path
- attachPathTrigger(obj, trigger) : attach a DynTrigger trigger to the obj. This trigger will start or stop the object motion along the path according to the triggerStop parameters of the trigger. The trigger should be a
- attachChangePathTrigger( obj, trigger, path, interval) : attach a ChangePathTrigger to obj. This trigger when activated will change the path of the object. The object will move to the start of the new path. This transition will last interval seconds.
- attachAnimateTrigger( obj, trigger, anim) : attach a AnimateTrigger to obj. This trigger when activated will activate anim animation of the object or stop any animation if anim is empty.
- activateAllDyn() : start all moving object along path

I have included in the waterworld mission file an example with different triggers. Go on the bride with your player to see their effects.

About the author

Real programmers don't waste time recompiling; they patch the binary files... ... Real programmers don't waste time patching binary files; they patch memory.

Page «Previous 1 2
#1
09/21/2002 (4:42 pm)
Is there any changes from the code you posted in the forum?
#3
09/22/2002 (9:42 am)
Ineed a lil help , i must not be understanding somthing, i have put all the code/script in the right places ( ithink) and recompile the engine and do see the new pathing in the waterworld mision www.planetquake.com/noescape/dev3/path.jpg

but now what? heres what i found in the console log:

*** LOADING MISSION: fps/data/missions/waterWorld.mis
*** Stage 1 load
*** Stage 2 load
Executing fps/data/missions/waterWorld.mis.
fps/data/missions/waterWorld.mis (0): Unable to find function cleanPathMission
fps/data/missions/waterWorld.mis (0): Unable to find function addPathDynamicObject
fps/data/missions/waterWorld.mis (0): Unable to find function addPathDynamicObject
fps/data/missions/waterWorld.mis (0): Unable to find function attachPathTrigger
fps/data/missions/waterWorld.mis (0): Unable to find function attachPathTrigger
fps/data/missions/waterWorld.mis (0): Unable to find function attachChangePathTrigger
fps/data/missions/waterWorld.mis (0): Unable to find function attachAnimateTrigger
fps/data/missions/waterWorld.mis (0): Unable to find function activateAllDyn
*** Mission loaded
Connect request from: IPX:41726561:284D69737369:28271
Connection established 1396
CADD: 1397 local

thanks
#4
09/22/2002 (11:27 am)
Look at your game.cs to be sure that it exec the file path.cs. All functions are defined in path.cs and you should have a line like exec("fps/server/script/path.cs"); in game.cs. (I have provided a game.cs file in the archive).
#5
09/22/2002 (11:50 am)
Frank,
I found that in the zip file that the example/fps/scripts directory is named "script" rather than "scripts". Other than that I had no problems with implementing this.

Thanks a ton for this resource. I was trying to do the same thing myself. You saved me some effort with the bonus of having some really nice bonus features like spline movement and easy to use editor features.

Also, it seems that the server/client is not fully in synch in the movement. Is there a way to setup the synchro variable to get this synched up more? or is there some other way that I'm not seeing?

Merci beaucoup!


Ace,
This is probably the problem that you are having too. If you have a fps/server/script/ folder move those two files to fps/server/scripts/ and it should work for you after that.
#6
09/22/2002 (1:21 pm)
Oops, there was a mistake, thanks for the tip.
Concerning the synchro between clients & server, there is a field in the datablock of dynShapeData. The name of the field is synchro. By default, its value is 0 which means no synchro between clients & server. If you set it to another value, it will mean that every synchro ticks (1/32 sec), the server will update the time of each client (synchronize it) for the path interpolation algo.
#7
09/22/2002 (1:33 pm)
heh, dummy me, i had everything correct, i just needed to delete the old game.dso.

It works awesome now, thanks.
#8
10/03/2002 (5:01 am)
Frank, very cool indeed!! One question though: do you have any plans for integrating collsion detection for the DynShape? Do you think that would be a problem?
#9
10/03/2002 (6:28 am)
Stefan,
Collision detection is working for me with this. Be sure to use a dts with collision info though. Also, it should collide more predictably if you set the synchro property on the dataBlock so that its in sync on the client and server.

Mike
#10
10/03/2002 (6:42 am)
Hm, strange, I tried the default player shape and a Realm Wars tree... both didn't collide with anything... mhm, guess I'll do some more tests... what shape are you using?
#11
10/03/2002 (7:45 am)
I'm using a custom object with its own set of collision masks.

I think the problem is that the Player object sCollisionMoveMask doesn't include the ShapeBaseObjectType which the dynShape is derived from. You could try adding the ShapeBaseObjectType object type to this variable. Not too sure if this is right collision mask though.

If that works for you, you could maybe add a new object type for dynShapes and include it in the collision masks for the objects you want to collide with it if you don't want your player to collide with all ShapeBase objects.
#12
10/03/2002 (9:51 am)
Mike, thanks for your help! I've tried both approaches... I've added the ShapebaseObjectType to the collsion mask in player and I've added a new objecttype called "DynShapeObjectType", witch I then added to the collision mask in player.cc and to mTypeMask in dynShape.cc, but none of that seems to work... the dynshapes are still moving right through my player... :/
Any other ideas? And do you know what this is supposed to do:
// We need to modify our type mask based on what our datablock says...
	mTypeMask |= (mDataBlock->dynamicTypeField & sgAllowedDynamicTypes);
Maybe I need to update the collision information in pack/unpackUpdate or something?
#13
10/03/2002 (10:47 am)
Stefan,
Try setting they synchro to something like 600 on the datablock? or maybe try it with a path where all the points are in the same location and see if you get a collision when it's not moving.

You know, I've been wondering about that dynamicTypeField thing myself. My best guess is that it is meant to flag a shape's datablock with whatever other object type you'd like in the script.
#14
10/03/2002 (11:26 am)
Hm, nope, still no collisions... :?
Maybe you could post some more details how you've implemented your DynShape object?
I'm also wondering what "noIndividualDamage" means...
#15
10/03/2002 (12:04 pm)
The dynShape will not stop if it collides with another object as it will keep moving on its path. However, the collided object should react.
Mayve, it can be an upgrade to the code.
#16
10/03/2002 (12:20 pm)
Frank, no, there doesn't happen anything when it collides with the player e.g. ...?
Ir just moves through everything ...
#17
10/03/2002 (1:44 pm)
Ok, i will look at it this sunday.
#18
10/07/2002 (7:45 am)
Frank, any news on the collision front? :P
#19
10/07/2002 (1:58 pm)
Sorry none as i was not all sunday on my computer. I should look at it soon.
#20
10/11/2002 (3:56 pm)
Frank,one more question... ;)
it seems that if you use a "one-way-path", the triggers work only once, also...
I'm using a dynObject for a sliding door with triggers in front and behind the door, but I can only trigger each trigger once. After the path is finished, nothing happens if I run through any of the triggers "connected" to my door object... is there any way to use one-way-paths more than once? Some way to reset them? I've played around with setStatic() and "triggered", but didnt have any luck... and what is the "powered" variable for, btw.?

Thanks a lot!! :)
Page «Previous 1 2