Game Development Community

Trap trigger

by Hindi · in Torque 3D Beginner · 03/13/2013 (1:15 pm) · 15 replies

Hi !

I'm doing my first personal exercises on Torque3D and I'm starting with a trap that kills the player when he enters the trigger volume. The code bellow shows the implementation for the trap animation, which is the problem here. The kill thing is already working fine.

I tryed several things and after few researches, I created an ItemData and a shapeBaseImageData :

datablock ItemData(SpikeTrapItem)
{
   shapeFile = "art/shapes/structures/buildings/Dirty/Spike_Trap.dae";
   cameraMaxDist = "0.798";
   class = "Weapon";
   image = "SpikeTrapImage";
   emap = "1";
   description = "Spike trap";
   friction = "0.58651";
   elasticity = "0.187683";
   category = "Weapon";
};

datablock ShapeBaseImageData(SpikeTrapImage : WeaponTemplateImage)
{
   shapeFile = "art/shapes/structures/buildings/Dirty/Spike_Trap.dae";
   shapeFileFP = "art/shapes/structures/buildings/Dirty/Spike_Trap.dae";
   Item = "SpikeTrapItem";
   animateOnServer = "1";
   firstPerson = "0";

And a trigger :
function PlayTriggeredAnimation(%objectToAnimate,%animationName,%animationLength)  
{  
  
     %objectToAnimate.playThread(0,%animationName);  
     %objectToAnimate.schedule(%animationLength, "stopThread",0);  
  
}

When I enter the trigger's volume, the console display something like :
Quote:Unknowned command playThread
Object SpkieTrapItem -> Weapon -> ItemData -> ShapeBaseData ...

I checked the documentation in the Torque3D files and I couldn't find the ShapeBaseData class, but there is a playThread method in the ShapeBase class. I though it's the same but I guess now that it's different ?

Also, my trap is turning all the time (like a pickable weapon). I think it comes from the "weapon" type, any idea how I can fix this ?

Thank you for your help !

About the author

I'm a student in Telecom SudParis, a French engineering school and I'd like to work in the video game industry as a programmer.

Recent Threads


#1
03/13/2013 (2:17 pm)
It kind of looks like the object you're sending to your animation function is the trap item itself and not the player.

Is this intended?
#2
03/13/2013 (2:18 pm)
Ok, I am not sure how to fix this, but I'll say that you should look at the AI Turret closely if you want a player-deployable trap object. I'm guessing in the trap inventory onThrow() you're going to want to create an object and drop it, but I'm not really that familiar with the turret.
#3
03/13/2013 (5:46 pm)
Quote:It kind of looks like the object you're sending to your animation function is the trap item itself and not the player.

Is this intended?

This is a spike trap I downloaded : http://opengameart.org/content/spyke-trap-low-poly-updated
I would like the spike to move up when the player enters the trigger's volume. As I started torque3D last night, I'm not really sure about what I'm doing, but I want the trap item to play the animation.

Quote:Ok, I am not sure how to fix this, but I'll say that you should look at the AI Turret closely if you want a player-deployable trap object. I'm guessing in the trap inventory onThrow() you're going to want to create an object and drop it, but I'm not really that familiar with the turret.

I'd like the trap to be a part of the level, not a droppable object. I'll still take a look at the AI turret tomorow, I'll probably learn a lot of things reading this.

#4
03/13/2013 (6:34 pm)
Ah, in that case, you might want to make it a TSStatic object, then just animate it in script by simply moving it. This way you don't get the ambient "bounce and spin" animation that pick-ups have.

Also, look at ambient animations for Torque objects - I'm sorry I'm being so vague but I haven't fiddled with this part of the engine in a long time.
#5
03/14/2013 (1:55 am)
Are you telling me that I should create two different objects (the base of the trap and the spikes) and move the spikes manualy ?

I read the documentation again and again and I think the ambient animation can only start when the level loads. I didn't find anything about any other animation (or even movement method) in the TSStatic class !
#6
03/14/2013 (5:46 am)
Let me do some research - I generally find that you get more information on this sort of thing reading the source code than reading the documentation.

[Edit]
Time out - your error message is telling you that ShapeBaseData does not have a playThread() method - and it in fact does not. You are passing the datablock in %objectToAnimate. I'm guessing you're passing %this from the trigger data callback; you need to pass the third parameter from that callback:
function myTriggerData::onEnterTrigger(%this, %trigger, %enteringObject)
I hope that does the trick for you. If not, I'll look some more.
#7
03/14/2013 (6:28 am)
I'm not sure that I understand your suggestion,

This is my TrapTrigger::onEntering() function :

function TrapTrigger::onEnterTrigger( %this, %trigger, %obj )
{
   %ID = %obj.getControllingClient(); 
   
   if (%ID)
   {
      //%obj.applyDamage(1000);
   }
   
   PlayTriggeredAnimation(nameToId("SpikeTrapItem"),"timeline",32);
   
}

The third parameter of myTriggerData::onEnterTrigger(%this, %trigger, %enteringObject) is the object that entered the volume. If I understand your suggestion, you tell me to pass the %enteringObject as the %objectToAnimate. I can't use this to start my animation (the animation should be played by the SpikeTrapItem).

When I try that :
PlayTriggeredAnimation(%enteringObject,"timeline",32);
There is no error because the Player has a playThread function, but nothing happens because the player doesn't have the "timeline" animation (the SpikeTrapItem has this animation).

I think the problem comes from a wrong type for my trap object, maybe the itemData objects aren't made for animations at all ?
#8
03/14/2013 (8:18 am)
Ok, I was at the gym and I realized that you need the trap object - sorry...

ItemData is not an object - it's a datablock. You need the actual object. Give the trap object a name, then add that name to a dynamic field (called, perhaps, trapObject) on the trap's trigger. Then you can do this:

function TrapTrigger::onEnterTrigger( %this, %trigger, %obj )   
{   
   %ID = %obj.getControllingClient();    
      
   if (%ID)   
   {   
      //%obj.applyDamage(1000);   
   }   
      
   PlayTriggeredAnimation(%trigger.trapObject,"timeline",32);   
      
}

nameToId() should not be necessary - the engine should look up the object by name automatically.
#9
03/14/2013 (8:57 am)
Ok, that makes perfect sense ! I didn't realise the item and the itemData are like the instance and the class. I feel so dumb !

Anyway, using this method I'm still trying to play an animation on a TSStatic object (which do not have any playThread() function). What type do you think I should use ?
#10
03/14/2013 (9:13 am)
Item and ItemData are related, but not in a class:instance relationship. Datablocks are server-side data collections (there are a few client-side datablocks, but mostly for particles etc.) that are part of Torque's network security scheme. They hold instance data so that the client in a multiplayer game can't alter server information - datablocks are sent from server to client once, and if the client alters them the server ignores those changes.

You can look at datablocks as descriptions of how you want an instance of an object to look when it is created.

My suggestion now is to look at the teleporter scripts. They create an animated teleporter pad using a TSShapeConstructor - hopefully looking at how that was done will help. The relevant scripts are art/datablocks/teleporter.cs, scripts/server/teleporter.cs and art/shapes/teleporter/teleporter.cs (that last is where the object is constructed).
#11
03/14/2013 (10:39 am)
I spent a lot of time reading this code and rewritting all I did on my trap in order to obtain the same architecture as the one used for the teleporter. Doing this, I learnt that the teleporter doesn't use any animation except the ambient animation. The animation performed during teleport is made out of particules...
Or I missed something !
#12
03/14/2013 (10:49 am)
Yes, the teleporter only uses an ambient animation. Upon further reflection, take a look at the soldier scripts too - might have to fiddle with something like this:

singleton TSShapeConstructor(TrapDAE)
{
   // construct your trap object
};

function TrapDAE::onLoad(%this)
{
   %this.addSequence( "trap.dae timeline", "timeline", 0, -1);
}
Or whatever the name of that animation is. We might have to get Dave Wyand in on this conversation....
#13
03/14/2013 (11:41 am)
The only sequence in the .dae is named ambient and it seems to be automatically loaded. I renamed it to be more obvious but, I don't see how I can do more...

singleton TSShapeConstructor(Spike_TrapDae)
{
   baseShape = "./Spike_Trap.dae";
};

function Spike_TrapDae::onLoad(%this)
{
   %this.setNodeParent("Spiketrap_spikes", "Arma_spiketrap");
   %this.setNodeTransform("Spiketrap_spikes", "1.34706e-006 -0.0216381 -0.0768489 -0.577509 -0.577233 0.577309 2.09404", "1");
   %this.setNodeTransform("Spikes", "0 -1.12947e-005 -0.00315087 1 0 0 0.00483374", "1");
   %this.setMeshType("Spiketrap_spikes 2", "normal");
   %this.setNodeTransform("Arma_spiketrap", "0 0 -0.058648 1 0 0 0", "1");
   %this.setBounds("-0.992645 -0.50306 -0.153634 0.603355 1.09294 0.0985038");
   %this.setObjectNode("Spiketrap", "Arma_spiketrap");
   %this.setObjectNode("Spiketrap_spikes", "Spikes");
   %this.renameSequence("ambient", "spikeUp");
}
#14
03/14/2013 (5:47 pm)
I think we're gonna have to call Dave. Jesse (animator/artist), Dave and I started to put together a paper on getting a character into the game with all of it's animations, etc. - and that would really help here. If you look, you'll see that the Soldier's animations are broken out into separate DAE sequences; I'm not sure if that's necessary, was done to make it easier to edit animations individually, or for some other reason.
#15
03/14/2013 (6:51 pm)
Hum ok... Would you mind asking Dave for more informations ?

I guess I didn't chose the right first exercise for learning how to use Torque3D... I didn't expect that to be so difficult. Well it's maybe not that hard, but we only miss some info.