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

instance_destroy on the other object using collision_line

dormi

Member
I have the following code in the step event of obj_bullet which is doing a collision check on obj_wall and then destroying the bullet.

if (collision_line(x, y, xprevious, yprevious, obj_wall, false, false)) {
instance_destroy();
}

How do I also make it destroy the obj_wall?

I have tried:

instance_destroy(other.id);

But I can understand why this hasn't worked.
 

Nidoking

Member
collision_line returns the id you would use. Instead of checking it like a boolean, store it in a variable and check whether it's noone. If not, destroy it.
 
I’m sorry I did not know you meant that, maybe try making a variable that stores the ID of the object you collided with something like “collision_line” and then use that ID?
 

FrostyCat

Redemption Seeker
Learn the difference between objects and instances.
Collision-checking functions: instance_place() and instance_position() are the instance-ID-oriented analogues of place_meeting() and position_meeting(). Functions that start with collision_ but don't end in _list all return instance IDs. Save that instance ID into a variable, then use that as the subject to work with. Note that these functions return noone upon not finding a collision. Always account for this special case whenever you handle collisions this way.
GML:
var inst_enemy = instance_place(x, y, obj_enemy);
if (inst_enemy != noone) {
    inst_enemy.hp -= 10;
}
GML:
var inst_wall = collision_line(x, y, xprevious, yprevious, obj_wall, false, false);
if (inst_wall != noone) {
    instance_destroy(inst_wall);
}
 

dormi

Member
Thanks for all your suggestions. The following code did the trick:

c_bullet_wall = collision_line(x, y, xprevious, yprevious, obj_wall, false, false);

if (c_bullet_wall) {
instance_destroy();
instance_destroy(c_bullet_wall);
}
 
Top