Triggers Firing too soon
by Henry Shilling · in Torque X 2D · 08/08/2009 (10:34 pm) · 11 replies
What defines the area that causes a trigger to trigger? I have a stationary object, like in a tower defense game that has a trigger component, it fires at a moving target when triggered. The object triggers before the moving object hits the trigger. I mean its like not even that close. if the moving object is passing by near the trigger object it fires the trigger. I have defined the collision area for both the trigger object and the moving target object. Makes no difference.


About the author
http://twitter.com/theBigDaddio
#2
08/10/2009 (1:59 pm)
How big is the bounding box for your truck. Maybe the trigger component ignores the collision areas and uses the whole object for the trigger. Another option would be to use the collision component and then write your own delegate for "trigger" This might then use the collision bounds.
#3
I actually ended up changing from triggers which was a very easy solution to using regular collisions, just allow collisions at rest for the helicopter. I would prefer that the triggers work correctly. The docs do nothing but say the objects bounding box. Now what is the objects bounding box? Not really explained anywhere. When I do a search in the Official TX documentation the only place you even find "Bounding Box" is in the Trigger definition.
The only thing I can think of is the component is forcing powers of 2 on my bounding box. That would make the helicopter 256x256? and the truck 32x32? I don't know. I dug through the trigger component code and really couldn't see anything. But then I am not the greatest C# coder.
08/10/2009 (3:01 pm)
The truck is what you see, so is the helicopter zone. They are shooting way further out than what I have pictured, sometimes they are 2x the helicopter zone away. The helicopter circle is 184x184, the truck is 18x45. I actually ended up changing from triggers which was a very easy solution to using regular collisions, just allow collisions at rest for the helicopter. I would prefer that the triggers work correctly. The docs do nothing but say the objects bounding box. Now what is the objects bounding box? Not really explained anywhere. When I do a search in the Official TX documentation the only place you even find "Bounding Box" is in the Trigger definition.
The only thing I can think of is the component is forcing powers of 2 on my bounding box. That would make the helicopter 256x256? and the truck 32x32? I don't know. I dug through the trigger component code and really couldn't see anything. But then I am not the greatest C# coder.
#4
08/10/2009 (4:05 pm)
I'll try this out when I get home today Henry to confirm if I see the same thing. I just implemented a trigger in my game as well but all seemed to work fine - but one of my objects is simply a blank scene object.
#5
08/10/2009 (11:19 pm)
Henry, i'm not that I was able to reproduce the same "problem" that you are encountering. I was able to confirm that the T2DTrigger OnEnter fires when the "bounding boxes" intersect - not the collision bounds. For sprites, the bounding boxes are the size of the image as far as I have seen. If you deselect all objects then click the edit button in the builder, you can then view the debug rendering rollout to see the bounding boxes of your objects. Perhaps they are bigger than you think for your objects.
#6
Normal:

Rotated:

08/10/2009 (11:59 pm)
Bingo! Thanks Jake, it seems that when the object rotates the bounding box does not. It expands to enclose the entire object. So when I rotate 45 degrees the bounding box doesn't rotate but expands in a very weird fashion. So now I have to rethink how I do my aiming.Normal:

Rotated:

#7
08/11/2009 (12:18 am)
Interesting....good to know. You could just use the collision component and user your own collision delegate to do what ever action you want...similar to the trigger but it should use collision bounds which I hope rotate with the object.
#8
You could edit the _OnRegister() method of the trigger class to auto-install the collision images that get created in the editor. Something like:
08/11/2009 (12:45 pm)
This is my reading of the trigger object. Collision images (which can be polygons) can be installed on a trigger, but it has to be done in code. For some reason the programmers have not made the trigger automatically pick up collision polygons that are added in the editor.You could edit the _OnRegister() method of the trigger class to auto-install the collision images that get created in the editor. Something like:
foreach (T2DCollisionImage image in SceneObject.Collision.Images)
{
InstallImage(image);
}
#9
I did a step through and it just jumps over this code. In the object _collisonImages = 0;
I added the InstallImage code and it works great!
08/11/2009 (2:55 pm)
This bit of code exists in the _OnRegister method of the trigger class.// init collision images
foreach (T2DCollisionImage image in _collisionImages)
image._sceneObject = SceneObject;I did a step through and it just jumps over this code. In the object _collisonImages = 0;
I added the InstallImage code and it works great!
#10
08/12/2009 (8:47 am)
Glad to hear that solved it for you.
#11
On an object that doesn't have a collision component it explodes.
I used:
instead.
04/02/2010 (9:23 pm)
If you use foreach (T2DCollisionImage image in SceneObject.Collision.Images)
{
InstallImage(image);
}On an object that doesn't have a collision component it explodes.
I used:
if(SceneObject.Collision != null)
foreach(T2DCollisionImage image in SceneObject.Collision.Images) {
InstallImage(image);
}instead.
Torque Owner Christian Rousselle
Default Studio Name