• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Destroying a specific object

F

Freedom2Fight

Guest
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:

Code:
if place_meeting(x,y-1,obj_Brick)
{
move_bounce_all(true)
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.
 
T

tserek

Guest
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
Code:
with(other){
  instance_destroy();
}
 
Top