Game Development Community

Door Animation

by Greg Cate · in Torque 3D Professional · 08/05/2011 (8:08 pm) · 2 replies

I have a Collada object with animations that I imported. The file was converted to dts, and I have split the "ambient" animation too two new sequences: opening and closing. After saving, I checked the cs file which reads as:
singleton TSShapeConstructor(Inn_door_cachedDts)
{
baseShape = "./inn_door.cached.dts";
};

function Inn_door_cachedDts::onLoad(%this)
{
%this.addSequence("ambient", "opening", "0", "27");
%this.addSequence("ambient", "closing", "27", "29");
}

OK, now on to my problem (warning: programming skills are good enough to get into trouble but not to know really how bad it is). I have created a trigger (called: InnDoorTrigger) that would call for the animation of the door to occur. I have also added script to the trigger.cs file as follows:

datablock TriggerData( InnDoorTrigger )
{
tickPeriodMS = 100;
};
function InnDoorTrigger::onEnterTrigger(%this, %trigger, %obj)
(
playThread("ambient", "opening", "0", "27");
)
On the trigger properties editor, it has onEnter, onLeave, onTick, but I am not sure as to what I should add or not to these areas.

I have been searching through the docs, forum and resources, but have found very little pertaining to this. Can someone please help or point me in the right direction?

#1
08/09/2011 (3:37 am)
What you are doing isn't as straight forward as you may hope.

To start off with I don't think you can play an animation on a TSStatic type object, which is what you get when you draw your model from under "Meshes".

I think the easiest way is create your door as a StaticShape.

To do that you need to type in somethign like:

datablock StaticShapeData (door1)
{
  shapefile = "art/shapes/actors/gideon/gideon.dts"; 
  category = "Doors";
};

You want to change the shapeFile to point at your door model and not the gideon model like I have.

The category field is what this object will be listed under in the world editor.

Look under the scripted section and there will be a new folder called "Doors" and inside this there will be "door1".

To play an animation on a staticShape you need to type in the ID number of the shape and then run the playThread function.

Something like:
1234.playThread(0, "run");
would play gideons run animation.

1234.playthread(0,"opening");
would play your doors opening animation.

The tricky part is getting your trigger to know the ID number of your door.

Once you have added your trigger and door to the mission, save the level and open the levels .mis file.

Down the bottom you should see the staticshape and the trigger listed.
The easiest way to do this is give your static shape a name and remember this name in your trigger.

Change it to look somethign like:

new StaticShape(doorNumber1) {
      dataBlock = "door1";
      position = "-0.614345 2.32741 240.802";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      canSave = "1";
      canSaveDynamicFields = "1";
   };
   new Trigger() {
      polyhedron = "-0.5000000 0.5000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
      dataBlock = "InnDoorTrigger";
      position = "0.913288 1.37939 241.446";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      canSave = "1";
      canSaveDynamicFields = "1";
      doorID = doorNumber1;
   };

You need to change the first line from
new StaticShape() {
to:
new StaticShape(doorNumber1) {

and add the second last line so it was:
canSaveDynamicFields = "1";
};

and will now be:
canSaveDynamicFields = "1";
doorID = doorNumber1;
};

This will create a variable inside your trigger called "doorID" and you will be able to use this to play the animation on the door.


Lastly, you need to change the code in your trigger function to:

function InnDoorTrigger::onEnterTrigger(%this, %trigger, %obj)
 (
   %obj.doorID.playThread0,"opening");
 )

Hopefully that will set you in teh right direction.
#2
08/10/2011 (5:49 pm)
Thank you so much for all of your help! Yes, you set me in the right direction. I was up all night long having fun. Work was a little tough the next morning - oh well one must sacrifice sometimes. I did have to make only one minor change to your code to get it to work where in the trigger function you had put:

%obj.doorID.playThread0,"opening");

I had to change this for some reason to

%trigger.doorID.playThread(0,"opening");

But other than that, your code worked beautifully, and I now have a better understanding of triggers thanks to your insight.

Thanks again,
Greg