• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Destroying a specific object

Hello everyone.

I was going through the tutorial for making a Breakout game and I figured I could translate the Drag and Drop bits in to GML.

It all works perfectly except for this bit:

if place_meeting(x,y-1,obj_Brick)
with(obj_Brick) instance_destroy();
The code above is placed in the step event of a ball (obj_Ball). It lets the ball destroy a obj_Brick it collides with. Well, this one destroys every obj_Brick once the ball hits any obj_Brick.

How do write it in a way that the ball only destroys the obj_Brick it collides with?

Thanks in advance.


Use instance_place that returns the colliding instance of object id. It is possible the ball can hit more than one brick on collide, you may like to use accurate position_meeting and instance_position check. Another way is to use lengthdir_ functions.
Last edited by a moderator:
If you use a collision event, the variable "other" will be the object that it is colliding with.

In obj_ball, create a collision event for the type obj_brick