• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GMS 2.3+ Setting collision properly when multiple objects share a collision parent

BQubed

Member
I've been working on pushing boxes in game and so far I got everything working except for one thing: boxes won't collide with each other. The problem is that all boxes in the game share the same collision parent object. So if I set collisions, then I need to set the object to be the collision object and when I do that, the box collides with itself. Is there a workaround for this?
 

Amon

Member
Check for the current instance of the box you are pushing.

GML:
var boxInst = instance_place(x,y, oBox);
if ( boxInst != noone )
{
    with (boxInst)
    {
        if ( place_meeting(x, y, other)    )
        {
            instance_destroy(self);
            instance_destroy(other);
        }
    }
}
The example above shows how to grab the current instance of a Box Object and check it against a collision with another using "other" in the place meeting collision function. When they collide, the current instance is destroyed as well as the 'other' instance it has collided with.
 

DaveInDev

Member
Seems weird.

If you use something like
GML:
inst_coll= instance_place(
    x+lengthdir_x(speed,direction),
    y+lengthdir_y(speed,direction),
    obj_par
    );
if(inst_coll)
{
    // treat the collision with inst_coll
}
in the step event of the parent object obj_par, and inheriting every step event of every child, you shouldn't detect autocollision. That's what I do in my game, without any self detection.

You can also use instance_place_list if you want to retrieve every collisions in the same event.

Please show your code if you want more help.
 
Top