Game Development Community

Help with Triggers activating objects in same group

by Roland Stralberg · in Torque Game Engine · 09/16/2005 (5:02 pm) · 4 replies

I want to activate a radar (an animated dts, which works with playThread )
when the player comes near it (not collides with it).

My plan was to place a Trigger which covers an area
around the radar and place both the trigger and the
radar in a SimGroup. According to the doc's triggers
will activate ::onTrigger on every object within same
group as the trigger.

The sad thing is that I cant get this to work.
When player enters the trigger my RadarTrigger::onEnterTrigger
is executed, but Radar::onTrigger is never called.

Can anyone help me with this problem. I have read similar
quiestions in the forum without been able to find what I'm
doing wrong. Would really appreciate any help.

Here is my code

// --- the radar
datablock StaticShapeData( Radar )
{
	category = "Misc" ;
	shapeFile = "~/data/shapes/radar.dts" ;
} ;

function StaticShapeData::create(%data)
{
	%obj = new StaticShape()
	{
		dataBlock = %data ;
	}
	return %obj ;
}

function Radar::onTrigger(%this,%obj,%trigger,%state)
{
	if ( %state == 1 )
		%this.playThread(0,"rotate") ;
}

// --- the trigger
datablock TriggerData(RadarTrigger)
{
 	tickPeriodMS = 100;
};

function RadarTrigger::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);
}


// In mission file
new SimGroup(RadarTest) {
      new StaticShape(R1) {
         position = "0.902434 11.622 0";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         dataBlock = "Radar";
      };
      new Trigger(T1) {
         position = "-2.10599 13.9702 -0.349939";
         rotation = "1 0 0 0";
         scale = "6.03268 22.0119 1";
         dataBlock = "RadarTrigger";
         polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
      };
   };

#1
09/16/2005 (7:44 pm)
You know, Roland, i'm having the EXACT same problem... If you put an echo inside the trigger, you will see that the message actually shows up on the console.log; wich means that the trigger works but the object linked to it doesn't respond... I'm having trouble even puting that simple flag tutorial to work! We're doing something wrong, wonder what could be...
#2
09/16/2005 (8:33 pm)
I'm no coder, but what Class or object is RayCone, isn't the object you're dealing with the "Radar"??
#3
09/17/2005 (2:28 am)
Rex:
You are right. RayCone is wrong.
I was a typo when writing this letter,
and i have corrected it now. The problem
is still the same though.

Thanks.
#4
09/17/2005 (7:07 am)
Now my problem is solved.
Thanks to Eric's thread Ridiculous Trigger Problem

All that needs get the radar working was following additon
function StaticShape::onTrigger(%this, %obj, %state )
{
	%this.getDatablock().onTrigger(%this, %state);
}

Many thanks Eric.