Game Development Community

Need help with an animated dts

by Devin D · in Torque Developer Network · 06/07/2009 (4:40 pm) · 16 replies

I just finished a tutorial to create a bouncing ball .dts with 3ds max. I can see the bouncing ball animation in the show tool, but when i place the .dts with the world editor it doesn't move. How do i add it to the world so it moves?

#1
06/07/2009 (7:54 pm)
Are you talking "move" as in using it as a player character?
"Move" as in kick the ball or hit the ball and it moves?
Or "move" as in it being animated when you place it in game -- ie. bounces in place?

If the latter, you'll need to tell it to play the animation you've created, otherwise Torque just considers it a non-animated staticshape. Assuming you already have an appropriate StaticShapeData(){}; datablock:
Foo::onAdd(%this, %obj)
{
    %obj.playThread(0, "FooAnimation");
}

The first one will require a new player datablock to be used.

The other one is a little more complicated...

If it doesn't have a datablock at all then it can only be dropped in-game as a TSStatic and those are simple objects that are little more than decoration or props.
#2
06/07/2009 (8:36 pm)
Its going to be the last one you said, animated when placed in the game bouncing in place. I'm sorry im not sure where to put that code, Could you tell me where to put it? I don't know what the "StaticShapeData(){}; datablock:" is.

If you know any tutorials relating to this subject that you think will help me out please tell me, they would help me out a ton.
#3
06/08/2009 (10:57 am)
A Staticshape is just one class of scripted item(s) in Torque, such as Item, Vehicle, Weapon, Player, etc. In order to get your scripted object to show up in the editor you will need a datablock for that object.
datablock StaticShapeData(BouncingBall)
{
    category = "Animated Props";
    shapeFile = "~/data/shapes/animatedProps/bouncingBall.dts";
};
category is where the object will show up under the Shapes tree in the World Editor Creator tree. Do not confuse this with the StaticShapes tree, since those are simple non-interactive objects. You can label this category as you want.

shapeFile will need to point to the filepath and filename of your object.

And this should kick off the animation sequence once it is added:
BouncingBall::onAdd(%this, %obj)  
{  
    %obj.playThread(0, "AnimationNAME");  
}
You will have to make sure that the "AnimationNAME" is the animation sequence you wish to use.

That code, the datablock and the onAdd() callback, can go anywhere in the server scripts that is executed. For organizational purposes you may want to create a new script file just for your object and exec it in game.cs along with the rest of the scripts.

So far as tutorials went, I never really used any, though I did find the ones on CodeSampler.com useful in the beginning. They're slightly dated but still relevant. You might find it of further value to read through all of the available documentation on the website and TDN also, though it TDN) may be of lesser accuracy.
#4
06/08/2009 (12:58 pm)
OK I think I understand better now, thanks for the help and the tutorials.
#5
06/08/2009 (1:09 pm)
I edited that codeblock up there when I saw your reply. I didn't notice the closing bracket or the semi-colon being cut off -- so be aware of that.

I hope those links help, it seems a huge leap at times, but just a little at a time as you go and you'll have a game before you know it. Always feel free to ask question, there are many people here who will try to help.
#6
06/08/2009 (1:31 pm)
Thanks for your help, I would have never figured any of this stuff out on my own. I didn't try that code yet, but thanks for fixing it :)
#7
06/08/2009 (8:20 pm)
I did like you said, created a new script and told it to be executed. I put that first piece of code in with my serverlogoitem.cs file and it seems to be ok. However with that second one:
1. BouncingBall::onAdd(%this, %obj)
2. {
3. %obj.playThread(0, "bounce");
4. }

I am getting a script compile error on line 3 for some reason, What did I do wrong?
#8
06/08/2009 (8:39 pm)
Hmm, I don't notice anything wrong with that offhand. The name of the object and animation sequence is different from what I'm using but that shouldn't affect anything.

Could you post the bit in the console.log where it mentions the script error? Maybe that will help me see the problem better
#9
06/09/2009 (6:34 am)
The only things I can think of is the name of the sequence must be wrong?

datablock StaticShapeData(BouncingBall)
{
   // The category variable determins where the StaticShape
   // shows up in the mission editor's creator tree.
   category = "Animated Props";
   shapeFile = "~/data/shapes/animatedProps/bouncingBall.dts";
};

function bouncingBall::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 continuously.
   %obj.playThread(0,"bounce"); //--IS THE SEQUENCE NAMED 'BOUNCE'?
}

What did you name the sequence in StudioMax?

Post the entire logoitem.cs file.

Tony
#10
06/09/2009 (11:23 am)
Yes i named it bounce in 3sd and it shows up as bounce in the torque show tool...
#11
06/09/2009 (11:39 am)
Start over. Don't use logoitem.cs

Create a new file called bounce.cs and paste this into it.


datablock StaticShapeData(BouncingBall)
{
// The category variable determins where the StaticShape
// shows up in the mission editor's creator tree.
category = "Animated Props";
shapeFile = "~/data/shapes/animatedProps/bouncingBall.dts";
};

function bouncingBall::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 continuously.
%obj.playThread(0,"bounce");
}


Then in server\scripts\game.cs exec it.

Run Torque and let us know what happens. If it doesn't work, post the last few lines of console.log here. I take great pride in my ability to get ambient animations to work ;) so don't worry. It will work, eventually.

Tony
#12
06/09/2009 (11:42 am)
I got it to work with infinitum3d's code, i must have mistyped the code somewhere.... THank you so much :)
#13
06/09/2009 (11:42 am)
Whoo hoo!

Great! Glad we could help :)

Tony
#14
06/09/2009 (3:02 pm)
Yeah, you have to beware of mistyped code :D

But glad you got it working.
#15
06/25/2009 (2:22 am)
hai friends... i tried above steps but still not working... i have attached the console file... can u help me...
Loading compiled script demo/server/scripts/radiusDamage.cs.
Loading compiled script demo/server/scripts/chimneyfire.cs.
Loading compiled script demo/server/scripts/item.cs.
Loading compiled script demo/server/scripts/weapon.cs.
Loading compiled script demo/server/scripts/flag.cs.
Loading compiled script demo/server/scripts/ambient.cs.
demo/server/scripts/ambient.cs (7): preload failed for BouncingBall: ShapeBaseData: Couldn't load shape "demo/data/shapes/animatedProps/bouncingBall.dts".
Loading compiled script common/server/lightingSystem.cs.
#16
07/30/2009 (3:37 pm)
hmm