Game Development Community

Animating a non player shape

by Todd Pickens · in Artist Corner · 03/20/2006 (4:21 pm) · 41 replies

Ok,

This is probably an easy one, but I have done a forums search and came up with nothing, and am in a hurry.

Anyone know how to get a non player shape to animate? In this case, it would be a windmill. I am exporting the animation in the .dts file, but get nothing. Do I need to set up the object in a script?
Page «Previous 1 2 3 Last »
#1
03/20/2006 (4:29 pm)
Haven't tried it, but this looks good.

edit: if that doesn't do it for you, search for "ambient animation".
#3
03/20/2006 (4:57 pm)
Thanks very much. Trying to wrap my brain around it now. It hurts.
#4
03/20/2006 (6:31 pm)
Ok, I have attempted to follow the resource provided above, but am stuck with the following error.

"preload failed for WindMill: ShapeBaseData: couldn't load ...yada yada yada .../windmill01.dts"

I have edited the staticShape.cs to include the example given, but pointed everything at my "windmill01.dts". I think what the instructions were saying was to added it to the staticShape.cs script.

Also, can anyone tell me what does the "0" do in this line "%obj.playThread(0,"wave");" from the example in the above resource.
#5
03/20/2006 (6:36 pm)
Man there was actually a website with a working windmill and everything let me try to find that
#6
03/20/2006 (6:55 pm)
Oh darn I'm having trouble finding this website I've done multiple searches and I'm not finding anything. So if you want me to email you the files I can it is quite a nice windmill with the animation.
#7
03/20/2006 (7:07 pm)
Master Treb, that would be great, please email them to me.

I am screwing something up in the scripts and can't seem to figure out what it is.
#8
03/21/2006 (9:46 am)
I believe it's the Thread 'slot' index. Does the sequence in question, "wave"; have the string 'wave' as the sequence/animation 'name'[within the actual sequence data]?? I have just done this type of shape recently and I'll look to see what I did...ah, here it is. The shape has many, many sequences as DSQ files loaded with the Constructor class object. When added, the vanes 'spin' as if under wind pressure[code not embedded], when the object is struck and damaged with a projectile, it 'pivots' on the it's axis.

function WeatherVane::onDamage(%this, %obj, %delta)
{
   echo("\c2WeatherVane-onDamage has been called");
   %ranNum = getRandom(2);
//   %obj.stopThread(1);
//   %obj.schedule(0, "playThread", 1, "pivot" @ %ranNum);
   %obj.playThread(1,"pivot"@%ranNum);
      echo("\c2WeatherVane-sequence pivot"@%ranNum@"\c2 has just been run");
      MessageAll('MsgAdminForce',"\c2WeatherVane-sequence pivot"@%ranNum@"\c2 has just been run");
//   %obj.schedule (970, "stopThread", 1);//another GGer suggestion
}

The above code will playThread the 'pivot*' sequence when the shape takes damage from a projectile....so it appears as though the sequence is perhaps not properly setup for exporting. How does the sequence look in ShowToolPRO??? or the -Mod Show? One of the 'first' things I do is check in my model/sequence viewer. I don't understand how folks can create art without the tool. The 'stock' model viewer was a cruel joke. Included with the price; but broken[at least for the longest time, hmmm fixed after the release of PRO??]

The scheduling was an attempt to get playThread to function as I think it should. At present, I believe that the engine does NOT reset the Thread on a shape after it's sequence has been run. I believe the engine 'thinks' it IS running the sequence, if; for example, the same thread happens to be run twice in a row, with the playThread calling... I tried moving the sequence to another Thread, but alas, TGE[at present] is not quite so user friendly to the artist who needs scripting. I believe it would take Source Code work to get a proper repeating thread, not a cyclic sequence, but consecutively run sequences. Closest I got was the scheduling of the stopThread to the length of the actual sequence. Worked 85% of the time, not 100%, would still refuse to play consecutive playThreads perfectly every once in a while.

...there 'should' be comments in Source Code about how playThread functions. When in doubt, look at code Comments.

Good luck.
#9
03/21/2006 (10:36 am)
Rex, not sure what you are saying there, sort of made my head hurt, too technical for me.

I am still working on the problem.

I am NOT using a DSQ, I am exporting the animation IN the dts. None of the examples given so far have solved my problem, as they all use DSQs for the animation.

Additionally , I only need the one animation, in this case a windmill with a turning fan.

Will post when I have solved this.
#10
03/21/2006 (11:08 am)
Can't you just export a repeated sequence as "cyclic"?
#11
03/21/2006 (11:11 am)
The link above to Ambient Animations with the StaticShape Class gives you all the code you need.

Are you sure the animation is ok? Does it work in ShowTool?
#12
03/21/2006 (11:13 am)
Sean, what do you mean? Do you mean export the .dts with the animation sequence called "cyclic"?

There is a check box in the exporter to make an animation automatically loop, which I have tried, but I get zero animation.

The more I work on this the dumber I feel, I think a coffee break is in order.
#13
03/21/2006 (11:22 am)
@ Sam3d


I figured the Ambient link was the way to go as well, but no success. Yes, the animation works fine in Show Tool.

I have to assume I am screwing something up.

For starters, what script do I add the stuff from the ambient example to? I thought it was suppose to be added to staticShape.cs, but go no success there.

Then I tried doing it as an independent script, and executed it in the games.cs

I am going to start from scratch and try again.
#14
03/21/2006 (11:23 am)
Thats not true, The original exampile uses animation embedded IN the model.

All you have to do it this...

Make a new .cs file named "windmill.cs"

Dont forget to exec it.....

Add all of this to that file.

//This is the part that asigns your new shape, in its animated form to the SHAPES catagory in the "Creator" //list, 
//NOTE: Do not use the shape (even if it is the same one) that is in the Static area of the "Creator" 
//window [b]IT WILL NOT ANIMATE![/b]
// Again just to make it clear. THIS PLACES THE ANIMATED SHAPE UNDER [b]SHAPES[/b] IN THE CREATOR //WINDOW, NOT UNDER STATIC SHAPES! The catagory asigned is "MISC", as oposed to "ITEM" ETC..

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";
};

// This function trigers the animation when the object is created in the world. Thats all it does.
// Things to be aware of is that the ___::onadd needs to have the SAME NAME as the function that sets it up //as a StaticShapeData in this case its FLAG... Also, You MUST have an animation In the DTS for this to work, 
//or merged DSQ (but we wont go over that here)... The animation this is trying to play is "wave" , this MUST 
//match the name OF the animation IN the object Exicitly! When you animated your shape, you should have 
//wretten down the name of the animation Case and all. And replace "wave" with that name. Wave being the 
//name of the animation. The 0 (zero) is the SEQUANCE NUMBER, this MUST MATCH, you cant play (1,"wave") 
//becouse wave is not sequance 1. its 0 (zero). If you want the animation to loop, this must be speficed on 
//export (whatever exporter you are using).

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");
}   


//this may or may not be defined somewere elese, it most likeley is, but its allways good to include it, unless //it will run the risk of over wrighting it.

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);
}

@Sean H: That wont triggewr the animation, but yes.

I hope this helps.

Check list:

1: make sure that the StaticShapeData(Flag) and the function Flag::onAdd(%this,%obj) match where it bold.

2: Make sure your new .cs is being Exec'ed

3: Make sure that the name of your animation is reflected correctly here
%obj.playThread(0,"wave");

4:make sure you add the object FROM THE SHAPES area of the world editor, not the Static shapes list.


If you did all that corectly, it will work.
#15
03/21/2006 (11:27 am)
Allyn, what parts not true?

Thanks for the information, I will take a careful look at it and see where I am screwing up at.
#16
03/21/2006 (11:28 am)
That the exampiles given use .DSQ's only... The Ambient Animations with the StaticShape Class is imbedded.
#17
03/21/2006 (11:31 am)
Allyn, correct. My mistake, I was referring to all of the other reference stuff provided.
#18
03/21/2006 (11:33 am)
NP, i hope i have explaned this well, spelling errors and all.

Once you understand this, you will be kicking yourself later at how easey it is. lol.
#19
03/21/2006 (11:37 am)
As a form of contrast, so you can see what was changed for somthing other than a flag...

This is one of my .cs files i made for one of the many objects in my game with "static" animations..lol

//---------------------------------------------//
//       **Butterfly animation set**           //
//                                             //
//  This script will make the Butterfly.DTS    //
//  animate when placed in the mission or,     //
//  when the mission is loaded, with the "Flap"// 
//  Animation imbeded in the DTS.              //
//---------------------------------------------//

datablock StaticShapeData(Butterfly)
{
   // The category variable determins where the item
   // shows up in the mission editor's creator tree.
   
   category = "Misc";
   shapeFile = "~/data/shapes/insects/Butterfly.dts";
};

function Butterfly::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,"Flap");
}   

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);
}

I use this same template for each and every one.
#20
03/21/2006 (11:41 am)
Allyn,

I have no doubt that I will be kicking myself. That is why I have been saying all along, that I am screwing something up.

Once I get this straight, I will make a truly FOOL proof tutorial on it so no one else has this problem :O)
Page «Previous 1 2 3 Last »