Triggers?
by Ryan Ackley · in Torque Game Builder · 07/12/2005 (10:47 am) · 3 replies
Is there support for a trigger object in T2D? I thought about using a static sprite with 100% alpha and just handling trigger like functions in an oncollision callback, but I got used to the idea of triggers in TGE. Is there anything like that in T2D (my own initial investigation says no, but then again, i just kinda skimmed)? Or ideas on a better way to handle triggers for events, etc? Thanks!
About the author
#2
07/12/2005 (11:44 am)
Hm, that seems like a more elegant solution than what I was thinking about doing (though, along similar lines). I'm only going to have one at a time (a trigger to end a level), or possibly 2 or 3 (to have a scripted sequence happen), so I wasn't really worried about overhead. Thanks for the ideas!
#3
07/13/2005 (8:32 am)
The way Gary has said is the way I've been doing it :) In fact one of the games I'm working on involves multiple "triggers" or "zones"... I'm going to set them up much like physical zones in TGE, where the physics change for the objects inside... the way fxSceneObject2D is set up with a callback works nicely for this :)
Torque Owner Gary Preston
// setup arena collisions $player1goalTrigger = new fxSceneObject2D() { scenegraph = t2dscenegraph; }; $player1goalTrigger.setPosition( "-50 -37" ); $player1goalTrigger.setSize( "1 170" ); $player1goalTrigger.setGroup( 3 ); $player1goalTrigger.setLayer( 0 ); $player1goalTrigger.setCollisionActive( false, true ); $player1goalTrigger.setCollisionMasks( BIT(2), BIT(2) ); // ball group and layer $player1goalTrigger.setCollisionPolyPrimitive("4"); $player1goalTrigger.tag = "player1goal"; $player1goalTrigger.setCollisionCallback(true);So long as your collission mask and group is setup correctly you will receive a callback on collission and can test if the tag is player1goal or something else.
I imagine using fxSceneObject2D is easier on the cpu than using a transparent sprite, although I've not done any tests to see.
BTW The above idea was pointed out to me by someone else in another post, but I can't seem to find it anywhere. Maybe it was in the old t2d forum and never got transfered over, or I just can't find it in my list :P