Game Development Community

Trigger

by Fucifer · in Torque Game Engine · 05/31/2007 (6:40 pm) · 3 replies

How do I excute a command with a trigger? Let say I want excute the quit(); command when player walk threw a door way. I know this is simple but just cant wrap my brain around it. Thanks.

#1
05/31/2007 (9:47 pm)
You place your desired command on the trigger's onEnterTrigger function. Of course, you have to detect what _kind_ of object entered first. In your example, it would be the datablock of your Player.
#2
05/31/2007 (10:10 pm)
The trigger automatically detects when the player enters the trigger, I don't think any other object types are detected.

So all you'd have to do is place the function in the onEnterTrigger function, as was mentioned above.

Example:
//-----------------------------------------------------------------------------
// DefaultTrigger is used by the mission editor.  This is also an example
// of trigger methods and callbacks.

datablock TriggerData(QuitGameTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};


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

function QuitGameTrigger::onEnterTrigger(%this,%trigger,%obj)
{
   // This method is called whenever an object enters the %trigger
   // area, the object is passed as %obj.  The default onEnterTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onEnterTrigger(%this,%trigger,%obj);
   quit();
}

function QuitGameTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
   // This method is called whenever an object leaves the %trigger
   // area, the object is passed as %obj.  The default onLeaveTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onLeaveTrigger(%this,%trigger,%obj);
}

function QuitGameTrigger::onTickTrigger(%this,%trigger)
{
   // This method is called every tickPerioMS, as long as any
   // objects intersect the trigger. The default onTriggerTick
   // method (in the C++ code) invokes the ::onTriggerTick(%trigger) method on
   // every object (whatever it's type) in the same group as the trigger.

   // You can iterate through the objects in the list by using these
   // methods:
   //    %this.getNumObjects();
   //    %this.getObject(n);
   Parent::onTickTrigger(%this,%trigger);
}
Pretty simple stuff really.
#3
06/01/2007 (6:14 am)
Thanks! I have been try all kind of way. I never thought it would be that simple. Tim your code work perfectly, Thanks.