Game Development Community

Animation triggers with static shapes

by Shaderman · in Torque 3D Beginner · 04/23/2010 (3:12 am) · 4 replies

I'm trying to make animation triggers work on a static shape (DTS) with the T3D binary.

I had neither success with my own shape using trigger 1 nor with the example shape from this resource.

I can see my trigger in the shape editor, but it looks like onAnimationTrigger() is never called.

This is the code I've used with that example shape:

datablock StaticShapeData(DemoObject)
{
  category = "Misc";
  shapeFile = "art/shapes/DemoObject/DemoObject.dts";
};

function DemoObject::onAnimationTrigger(%this,%obj,%trigger)
{
    error("MOO!");
}

There are no errors in the console, the animation of that example shape can be played but I don't see anything from the onAnimationTrigger() callback.

Are animation triggers supposed to work at all?

Thanks,

Shaderman

#1
05/27/2010 (2:02 am)
Have you already a solved this problem? I have done the same thing but I don't get it working. When rebuilding the code there are no errors, but the onAnimationTrigger is never been called (at least when I debug it).

There is something in this resource but this is only in the player class. I don't know if this works because I didn't try it yet.

edit: don't know if a similar function is in the staticshape class.
#2
05/27/2010 (2:26 am)
Richard, I wasn't able to solve this problem. I thought I had read somewhere about staic shape animation triggers being part of T3D but I doubt they are (maybe in newer versions than the binary) or something like the callback name changed.
#3
05/28/2010 (5:29 am)
I got it working under TGE. Maybe you can use the code in T3D:
In shapeBase.cc near line 2072 i wrote this:
void ShapeBase::updateThread(Thread& st)
{
   // get the Animation Trigger
   if (mShapeInstance && !isGhost()) 
   {
      for (U32 i = 0; i < 33; i++) 
      {
         if (mShapeInstance->getTriggerState(i)) 
         {
            char slot[3];
            dSprintf(slot,sizeof(slot),"%d",i);	
            Con::executef(mDataBlock, 3 , "onAnimationTrigger" , scriptThis(), slot);
         }
      }
   }  
   // .... other code
}

Example code in TorqueScript:

function db_animTrigger::onAnimationTrigger(%this,%obj,%trigger)  
{  
   echo("AnimationTriggerEvent");
   switch (%trigger)
   {
      case 1:
         echo("Frame No. 20");
         if (%obj.anim == "atest")
         {
            %obj.stopThread(0);
            %obj.playThread(0,"btest");
            %obj.anim = "btest";
         }
      case 2: 
         echo("Frame No. 50");
         if (%obj.anim == "btest")
         {
            %obj.stopThread(0);
            %obj.playThread(0,"atest");
            %obj.anim = "atest";
         }
      case 3:
         echo("Frame No. 150");
      default: 
         echo("");
   }
}
#4
06/01/2010 (2:42 am)
@Thomas,

Thanks. I had it working already when you posted it (made a terrible typo error).

As for the T3D users: you don't need the preliminary 3 in this line:
Con::executef(mDataBlock, 3 , "onAnimationTrigger" , scriptThis(), slot);

//change it in:
Con::executef(mDataBlock, "onAnimationTrigger" , scriptThis(), slot);