• 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!

Simple destroy instance

K

kilnakorr

Guest
Hi

I'm new to GM (did some looong time ago and forgotten most of it), and the new layout isn't helping.
I'm trying to start out with something simple, but stuck since most guides doesn't really match what I'm trying to do:

Basically I want to destroy an instance when it reaches a certain y position, so it doesn't continue out of the bottom of the screen.

What's the easiest way to do this?
I found this little bit of easy code:

var inst = instance_position(x, 300, obj_vmgbomb);

if inst {
with inst instance_destroy(obj_vmgbomb);
}

Either it's not correct of I'm not running the script right.

Any ideas?
 

CloseRange

Member
in obj_vmgbomb step event:
Code:
if(y >= 300) instance_destroy();
if you want it to be destroy outside the room there is a event called 'outside room' in the other tab. just put instance_destroy() there and it will be destroyed when it leaves the room.
 

rytan451

Member
Something that guarantees that the object is out of the room before destroying it:

Code:
//@desc Step event: destroy object if it is below the room

if (bbox_top > room_height) {
    instance_destroy();
}
What this does is checks if the top of the object (bbox_top) is below the bottom of the room (room_height).
 
Top