Game Development Community

Ambient Animation

by Spencer Strombotne · in General Discussion · 08/11/2008 (8:54 am) · 5 replies

I have a dts object that has a an ambient sequence that plays the same thing over and over again in a loop. I opened it with the show tool and the animation plays but when I try to load it into my game it just sits there. Does it have to be a specific datablock type? Do I need to trigger the animation somehow?

#1
08/11/2008 (9:05 am)
You have to write this code in any server side script file or just create a new file for example animShapes.cs and place in the server script directory and exec the script in game.cs then write this code inside that.
datablock StaticShapeData(myFirstAnimShape)
{
   category  = "Animated";
   shapeFile = "~/data/shapes/animated/yourShape.dts";
};

function myFirstAnimShape::onAdd(%this,%obj)
{
   %obj.playThread(0,"ambient");
}
and write the path to your shape file in the shapeFile field in the datablock above.

and remember to place the object from shapes not from staticShapes in the editor. It will be inside the Animated category.

Hope this helps...

:)
#2
08/11/2008 (9:25 am)
The onAdd function is never called but if I type the command in manually from the console it starts to animate. Should I just place it in the create function instead?
#3
08/11/2008 (9:58 am)
NO... the onAdd function works perfectly, I've used it in many animated shapes, and the onCreate function is called when you create a shape in the editor, so it wont play the animation when you save a mission and load it again with the shapes created. So onAdd function is to be used. Check the myFirstAnimShape name if you changed it. It should be the datablock name and the onAdd function is called with that name.
#4
08/11/2008 (12:26 pm)
You could also link the playthread/stopthread commands to triggers in-game. No point having an animation playing that the player isn't in the area to see. Same goes for FX (though when that's particle emitters it's usually a case of spawn/delete).