Game Development Community

Checking to see if multiple objects are touching

by Doug Barnes · in Torque X 2D · 10/10/2007 (1:11 pm) · 1 replies

Hello,

So what I want to do is see if three or more of the same object are colliding with each other. Right now I can see if two of the same object are touching through this method
static void OnCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
        {
            if (ourObject.Name == theirObject.Name)
            {
                ourObject.MarkForDelete = true;
                theirObject.MarkForDelete = true;
            }
        }
but I cant see to think of a way to do this so that I know if more are touching. Any suggestions would be helpful.

Thanks,
Doug

#1
10/13/2007 (2:19 pm)
Is this perhaps part of a "match3" style game? It might be possible to not use collisions at all (depending on the specifics of your game), instead if each "gem" has a position on a tilemap you can query the surrounding tile values when it comes to a stop.

If you do wish to use collisions for this the specifics of how it could work would depend once again on your specific game.

If a piece collides with another I assume it stops and has perhaps sticky collision response to keep it from penetrating the other piece. So, in oncollision you can store what type of piece it has collided with. Then when the third pieces collides with the second you check first if they are of the same type and if the second is in contact with another of the same type (my checking the dynamic field you stored this in).

A third option could be to use methods in the scenegraph like findobjects (i forget the actual method, like pickrect in TGB) to get objects in the vicinity of the collision and test them for type at that point.