Game Development Community

Scripting animation and/or keyframes with State System?

by Infinitum3D · in Torque Game Engine · 11/24/2008 (11:01 am) · 7 replies

I have a simple door animation. Keyframes 0-50 are the door opening to 90 degrees, frames 51-100 are the door closing again.

Can someone guide me to the correct to script a function that calls the correct keyframe sequence on collision?

I know I need a datablock for the door, but I don't have a clue about the function onCollision.

Or does it have to be done in the engine?

Thanks!

Tony

#1
11/24/2008 (1:04 pm)
I don't think you can call keyframes from script. You can only play specific animations. So if you had thor open in one sequence and your close in another, you'd be able to play either on collision when appropriate.
#2
11/24/2008 (3:07 pm)
Thanks Daniel,

I don't suppose you know how to set up two sequences in StudioMax?

No? That's OK. I'll look it up.

Tony
#3
11/26/2008 (8:35 am)
It is possible to play specific keyframe ranges,but you need to write your own code for it.
You need to update ShapeBase::advanceThreads()
Look at Plastic Jem tutorial #2.
#4
03/24/2009 (7:47 am)
OK, so I've made a change.

I now have a door.dts with two separate animation files, doorOpening.dsq and doorClosing.dsq

During the opening and closing animations, the door, bounds, and Col-1 all pivot around the hinge. This should allow the collision mesh to pivot into and out of the doorway as the door opens and closes.

I'm trying to script a simple onCollision test, but I need to tell the door when it is open and when it is closed.

For example:

If OPEN
then onCollision
play.doorClosing.dsq
else
play.doorOpening.dsq

Any suggestions?

Looking at Crossbow.cs I see stateName[0] = "Preactivate";

I think this is how I need to do it, but I thought the State system was only for mounted images?

Thanks,
Tony
#5
03/24/2009 (9:38 am)
Following crossbow.cs as a guide, I wrote a State script for my Door.

// Torque Game Engine 
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

datablock ItemData(Door)
{
   category = "Doors";
   shapeFile = "~/data/shapes/doors/metaldoor.dts";
   emap = true;
   image = BasicDoorAnimImage;
};

datablock ShapeBaseImageData(DoorImage)
{   // Basic Item properties
   shapeFile = "~/data/shapes/doors/metaldoor.dts";
   emap = true;

   // Initial start up state - door is closed, ready to be opened
   stateName[0]                         = "DoorIsClosed";
   stateTransitionOnCollision[0]       = "OpenDoor";

   // Door is being opened
   stateName[1]                           = "OpenDoor";
//   stateSequence[1]               = "open_door";
   stateSound[1]	= "DoorOpeningSound";
   stateTransitionOnTimeout[1] = "DoorIsOpened";
   stateTimeoutValue[1] = 0.5;

   // Door is opened and ready to be closed
   stateName[2]                          = "DoorIsOpened";
   stateTransitionOnCollision[2]   = "CloseDoor";

  // Door is being closed
  stateName[3] = "CloseDoor";
  stateSequence[3] = "close_door";
  stateSound[3]	= "DoorClosingSound";
  stateTransitionOnTimeout[1] = "DoorIsClosed";
  stateTimeoutValue[1] = 0.5;
};
//--TODO; 
//--add DoorIsLocked (need key to get in)
//--add DoorIsUnlocked (transitions to OpenDoor)
//--add DoorIsBarricaded (need to break down door, transitions to DoorIsDestroyed)
//--add DoorIsDestroyed (replace door.dts with doorDebris.dts)


//-----------------------------------------------------------------------------

It doesn't work. My door simply spins in a continuous circle, AND there is no collision at all. It must have something to do with this script because I can place the door as a StaticShape and the collision works just fine.

I can take a door from another source, place it as a Static Shape and it is solid as well (working collision mesh), but if I put that solid door into my script as shapeFile = "~/data/shapes/doors/solid_door.dts";, it spins in a continuous circle also, and also has no working collision mesh at that time.

Any help with a State System would be greatly appreciated!

Thanks,
Tony
#6
03/24/2009 (11:02 am)
OK its not gonna work.

According to Stephen Zepp in thread 16049
"It's imporant to note that the ShapeBaseImage system expects all weapon animations to be within the weapon's dts, not as separate dsq files. DSQ files are only intended to be used at the player class level in the hierarchy."

Back to the drawing board.

Tony
#7
03/25/2009 (2:28 pm)
The item by default is not collidable.
There is an additional resource for it.