Game Development Community

OffCollision?

by Deozaan · in Torque Game Builder · 11/19/2007 (9:05 pm) · 10 replies

Is there an easy way to be notified when an object leaves another object's collision boundaries? Kind of like WorldLimits, except on an object to object basis?

And actually, I don't care about objects that never were colliding with the specific object, but one that was colliding that left. A one-time callback upon leaving collision boundaries.

#1
11/19/2007 (9:30 pm)
It sounds to me like you should be using triggers rather than collisions. If I am incorrect, the easiest way to do it would be to mount a trigger to the object in question. Then ensure the onLeave callback is enabled.
#2
11/19/2007 (9:56 pm)
Awesome! I think that's exactly what I need!

Thanks Phillip!
#3
11/23/2007 (5:52 pm)
Keep in mind TGB doesn't handle multiple overlapping objects very well. For instance, If you have one object simultaniously overlapping two other objects it will register a constant collisions, but only with ONE of them.

Just something to watch out for, don't corner yourself into a situation where you need objects to be registering collisions after they are already overlapping.
#4
11/23/2007 (6:23 pm)
Okay, so here's what I'm trying to do:

I've got towers that can target enemies within a certain range. But they will only pick one target to shoot at within that range. I want them to be kind of smart and diverse in the way they choose their target, so what I want to do is when an enemy comes within range, it gets added to a list, then the tower decides which of all enemies on it's list of targets to choose and shoot at.

As far as the list is concerned, I only care about enemies when they come within the range and when they leave the range, but there might be multiple enemies within range at the same time.

I was planning on using collisions until Phillip said Triggers might be better. Do triggers have the same problem James mentions? I don't care if it is constantly colliding. I just need to know when they enter and exit the range radius.
#5
11/23/2007 (9:19 pm)
Triggers sound like a good idea for your circumstance. I think it would be ideal to do something like this:

function TriggerClass::onAddToScene(%this, %sceneGraph)
{
    %this.potentialTargets = new SimSet();
}

function TriggerClass::onEnter(%this, %object)
{
    if (!%this.potentialTargets.isMember(%object))
        %this.potentialTargets.add(%object);
}

function TriggerClass::onLeave(%this, %object)
{
    if (%this.potentialTargets.isMember(%object))
        %this.potentialTargets.remove(%object);
}

To answer your question, no, triggers do not suffer from the same *problem*. I say *problem* because continuous collisions are not something that you want in your game, if it is, then there is usually something you can do to prevent the use of them. The reason? If there is a collision every frame, then the amount of work that goes into processing it and outputting it is incredible (believe me, the code structure is massive). The only collision that is detected, is the one that has the smallest collision time.

With triggers, every object entering/leaving the bounds of the trigger is detected and reported, which is why triggers are perfect for you.
#6
11/24/2007 (10:05 am)
Thanks a lot Phillip! Sounds great!
#7
11/24/2007 (12:49 pm)
Another option is to just do a pickrect() or pickradius() before you shoot, and pick the most appropriate object found to target.

This method wouldn't require a separate trigger object mounted to each of your guns.
#8
11/24/2007 (3:55 pm)
With that information, I suppose it becomes a question of efficiency. Any ideas on whether it would be more efficient to use a trigger that only certain objects will set off and thus be added to a list or to sort through any and all objects that may be within a radius?
#9
11/24/2007 (9:56 pm)
I think triggers would be a better option. Triggers basically just check to see if objects are within the bounds of the trigger object, which is exactly what a pick function does as well. Triggers sort through most of the rubbishy objects (gui and misc objects) and only report scene objects, whereas pick functions report everything (I think they also report scenegraph/window + gui elements, though I could be mistaken). So, in terms of efficiency, I think they're pretty similar.
#10
11/28/2007 (6:03 pm)
Thanks again. Now I've got some more questions about triggers, which might still be related to Collision.

How is a trigger activated? By the Trigger's Collision settings?

Should I configure it to use circle collision, receive collision, and enable callback?

What I'd ultimately like to do is use a Behavior to do all this stuff for me with minimal modification on my part, as I intend to have many towers and objects use the triggers to get lists of objects in range.