Ambient Animations with the StaticShape Class
by Tim Gift · 09/30/2001 (10:22 am) · 26 comments
Ambient animations are usually background animations such as plant swaying, flag waving, etc. They are typically started when the object is constructed and run continuously. This is an example of starting an ambient animation on a static shape using the StaticShape base class/datablock.
In this example we declare a new datablock type call "Flag" and override it's onAdd method to start the animation on the new object. All instances of the "Flag" object will exec this same onAdd script.
The StaticShapeData::create method is provided here only because it's not part of the SDK 1.0 example. This is normally part of your game's basic script support, and is included in the fps demo (SDk 1.2 or higher).
This code also needs to get executed after the server is created. For SDK v1.0: if you put this into a file, it should be executed from the createServer function in server/scripts/server.cs, or by putting into an existing script file executed by createServer, such as player.cs.
If you have version v1.2 or higher (which you won't at the time I'm posting this) you can add new files to the fps mod's createGame function mod in fps/server/scripts/game.cs
If the script is executed properly, you should see the Flag object in the mission editor's create tree under the Shapes/Misc category.
In this example we declare a new datablock type call "Flag" and override it's onAdd method to start the animation on the new object. All instances of the "Flag" object will exec this same onAdd script.
The StaticShapeData::create method is provided here only because it's not part of the SDK 1.0 example. This is normally part of your game's basic script support, and is included in the fps demo (SDk 1.2 or higher).
datablock StaticShapeData(Flag)
{
// The category variable determins where the item
// shows up in the mission editor's creator tree.
// (this is misspelled in v1.0, v1.1 or higher should
// use the correct spelling "category")
catagory = "Misc";
shapeFile = "./flag.dts";
};
function Flag::onAdd(%this,%obj)
{
// %obj is the object being added to the world
// with %this datablock. Start up a thread on the
// new object. Since the wave sequence is cyclic
// this animation will run continously.
%obj.playThread(0,"wave");
}
function StaticShapeData::create(%block)
{
// The mission editor invokes this method when it
// wants to create an object of the given datablock
// type. You only need one of these methods for any
// class/datablock type (in this case StaticShape).
%obj = new StaticShape()
{
dataBlock = %block;
};
return(%obj);
}For this example to work correctly, you need a flag.dts shape with a cyclic animation called "wave".This code also needs to get executed after the server is created. For SDK v1.0: if you put this into a file, it should be executed from the createServer function in server/scripts/server.cs, or by putting into an existing script file executed by createServer, such as player.cs.
If you have version v1.2 or higher (which you won't at the time I'm posting this) you can add new files to the fps mod's createGame function mod in fps/server/scripts/game.cs
If the script is executed properly, you should see the Flag object in the mission editor's create tree under the Shapes/Misc category.
About the author
Recent Blogs
• Plan for Tim Gift• Plan for Tim Gift
• Eclipse Project for Torque
• Scene Lighting Patch
• Plan for Tim Gift
#2
11/20/2001 (6:12 pm)
How many threads are available for animation under the torque engine?
#3
11/21/2001 (9:17 am)
ShapeBase provides four threads (and four sound channels), though the core engine itself doesn't have a set limit.
#4
01/19/2002 (9:48 am)
Short and good. Useful to me too =0)
#5
01/31/2002 (1:22 pm)
Exactly what I needed. Thanks. :)
#6
(I'm considering using this for trees, but I was planning on havingmore than 4 of them)
03/20/2002 (4:56 am)
So with four threads, does that mean there can be max 4 flags in one mission?(I'm considering using this for trees, but I was planning on havingmore than 4 of them)
#7
03/25/2002 (10:33 am)
No Bendik, each flag can have up to four threads running. You can have as many flags as you like.
#8
04/02/2002 (3:25 pm)
Could you please update this as the code no longer works.
#9
Just thought I would mention that!
05/16/2002 (10:35 pm)
It took me a while to get this code to work. My error was the "category" typo (look in the comments of the code). Silly mistake as it was explained right there. Just thought I would mention that!
#10
%obj.playThread(0,"ambient");
06/21/2002 (9:46 pm)
If you're using Milkshape, by default the animation sequence is named "ambient." So your playThread call in Whatever::onAdd(%this,%obj) would be:%obj.playThread(0,"ambient");
#11
Edit: Object 'trees' is not a member of the 'GameBaseData' data block class
fps/server/scripts/staticShape.cs (16): Register object failed for object (null).
01/10/2003 (4:28 pm)
I get a gamebasedata error?Edit: Object 'trees' is not a member of the 'GameBaseData' data block class
fps/server/scripts/staticShape.cs (16): Register object failed for object (null).
#12
02/17/2003 (5:42 pm)
it seems like it doesn't work for shapebase. In other words onAdd doesn't work for shapbase. Hints?
#13
05/28/2003 (2:02 pm)
This is a good tutorial but how can i use this technique with the animation files of max? This seems only to work with milkshape. It would be a lot of help thanks chris
#14
05/28/2003 (7:19 pm)
Chris, this will work for any dts file that contains animations... it doesn't matter which modeler was used to create it.
#15
Anyone know what the problem might be?
Edit: I think I found the problem. I had something else in my mission with the same name. After I changed it, it worked.
07/11/2003 (3:05 pm)
I'm getting the EXACT same error as Edward. Yes, my object has animations and works in the ShowTool. :/Anyone know what the problem might be?
Edit: I think I found the problem. I had something else in my mission with the same name. After I changed it, it worked.
#16
11/02/2004 (3:46 am)
help me please ive had a problem with this for ages now got in an animating but in god mode or walking i collide with the ambient model and it crashes any ideas people thanks in advance email me X00001104@itnet.ie
#17
12/18/2005 (11:11 am)
This does work with 1.4 =)
#18
01/04/2006 (10:44 pm)
I got my animation to run in showtools but not in Torque. I then figured out that while my sequence node name must start with "Sequence_" I must not refer to it that way in the script. E.g. Sequence node named "Sequence_wave" will be refered to as "wave" in the script: '%obj.playThread(0,"wave");'
#19
is the collision box also animated?
And when i walk with my character between the pieces that stick out, will my character move around as it is being pushed by the gear?
i hope i explained my question wel?
peace
06/26/2006 (1:11 am)
i have a question, lets say, i make a giant Gear, and it rotates, and it has a collision box, is the collision box also animated?
And when i walk with my character between the pieces that stick out, will my character move around as it is being pushed by the gear?
i hope i explained my question wel?
peace
#20
09/18/2006 (10:30 am)
Ok, who would have a clue to what the problem is here: I want to add a rocket launcher in the game for players to pick up, when i try and add it i get this error: "Object 'RocketLauncher' is not a member of the 'GameBaseData' data block class". Here's the funny thing, it's the exact same as crossbow.cs. Crossbow, crossbow ammo, rocketLauncher Ammo can all be added to the mission, but not RocketLauncher. If I choose a different level it works, but not this particular level. Why not, why would it not work for this one level?? Anyone have idea, please help. Thx 
Torque Owner Karsten "Clocks" Viese
// Clocks out