Game Development Community

Can't figure out how triggers work on T2D 1.7.6 Window 7 64bit

by Andy Hawkins · in Torque Game Builder · 05/14/2012 (5:58 pm) · 8 replies

I've placed a trigger in my 2d scene. It's got enter and leave callbacks ticked. I've given it the class name "trigger" and exec'd this script. However when I set a break point inside the onEnter function it never gets in there. Is there something I'm missing?

function trigger::onEnter(%this, %object)
{
   // Set the player to collide with only the trigger's graph group, thus disabling collisions
   // with the platforms.
   //%object.setCollisionGroups(1);
   // which trigger is this?
   if (%this.getName() $= "EndLevel1")
   {
      // teleport to StartLevel2
      %pos = StartLevel2.getPosition();
   }
   // which trigger is this?
   if (%this.getName() $= "StartLevel2")
   {
      // teleport to EndLevel1
      %pos = EndLevel1.getPosition();
   }
}

#1
05/14/2012 (6:17 pm)
I haven't actually gotten any triggers to ever work. They've messed with gravity that I'm making use of, and so I never really bothered to make sense of them.

Sadly, I can't help. Though if anyone has any idea why triggers messed with my gravity, I'd love to hear ideas.
#2
05/14/2012 (6:54 pm)
I'd recommend using them with behaviors.
#3
05/14/2012 (7:22 pm)
We'll what's the point of using triggers then? Are they broken? I may as well just use a scene Object with collision detection on. Shame :(
#4
05/14/2012 (10:02 pm)
Do you have Send/Receive Collisions set for the trigger and object ?
#5
05/14/2012 (11:38 pm)
Scene objects with collision doesn't work as good as triggers when you want an object to be able to move over it without being affected/pushed by the object it collides with.

To me it looks like your set up should work, as long as the trigger and the player have correct send/receive collisions set.

I have had some problems with large trigger areas though. The onStay callback only seems to get called as long as the collision borders overlap and not when an object is completely within the trigger area.
#6
05/15/2012 (7:11 am)
Andy,

Your code works fine for me. I just had to make sure my test player had "Send Collision" checked and my trigger had "Receive Collision" checked.

Also, make sure a collision polygon is defined for both the trigger and the item you want to fire the trigger.
#7
06/16/2012 (4:18 am)
I'm finding this thread describes my problem. Really has no-one fixed this yet?
www.garagegames.com/community/forums/viewthread/76932
#8
06/16/2012 (5:20 am)
Well I'm over this... here's my behavior to solve all this mess. Please use this as it works really well :)


1) Add a global to point to your player, called $player.
2) Create a sceneObject, named MyTrigger and drop this behavior on it.
3) Turn off all collisions for this.


//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
// 
// behaviour written by Andy Hawkins 2012
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
// 
// behaviour written by Andy Hawkins 2011
//-----------------------------------------------------------------------------

if (!isObject(MyOwnTrigger))
{
   %template = new BehaviorTemplate(MyOwnTrigger);
   
   %template.friendlyName = "User Defined Trigger.";
   %template.behaviorType = "System";
   %template.description  = "Check to see if player has entered area.";
   
}

function MyOwnTrigger::onLevelLoaded(%this)
{
   %this.owner.enableUpdateCallback();
   %this.insideTrigger = false;
}

function MyOwnTrigger::onUpdate(%this)
{
   // get the extents of this scene object
   %area = %this.owner.getArea();
   %minX = getword(%area, 0);
   %minY = getword(%area, 1);
   %maxX = getword(%area, 2);
   %maxY = getword(%area, 3);
   
   // get the player position
   %x = $player.getPositionX();
   %y = $player.getPositionY();
   
   // test to see if the centroid of the player is inside this.
   if (%x >= %minX && %x <= %maxX && %y >= %minY && %y < %maxY )
   {
      %this.insideTrigger = true;  // yes it is 
   }
   else
   {
      %this.insideTrigger = false; // no it isn't
   }
   
   // resolve trigger events
   if (%this.insideTrigger && %this.owner.getName() $= "Exit" )
   {
      // TODO add your outside trigger code here
   }
   // turn off the prompt text
   if (%this.insideTrigger == false && %this.owner.getName() $= "Exit" )
   {
      // TODO add your inside trigger code here
   }
}