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

GameMaker Help With Bullet Collision line

FoufaDjo

Member
so am trying to make a fast bullet collision for my game but i have problem with targiting the enemy object sometimes i i think its becaue that the event_preform start sometimes when the enemy object is destroyed so the collision event cant find the enemy id if you guys have any idea to how to fix this pleas let me know

The bulletEndStep Event :
if hit = 0 && collision_line(xprevious,yprevious,x,y,obj_enemy,1,0){
event_perform(ev_collision,obj_enemy);
}

The Bullet Collision Event With The Enemy :
if other.life = 0{
other.hp -= dmg;
hit = 1;
}
 

CloseRange

Member
obj_enemy refers to all enemys. If you try to use it as an instance it won't guarantee what instance will be used.
you use event_perform on obj_enemy instead of the instance that the bullet collides with.
Perhaps try this:
Code:
var o = collision_line(xprevious,yprevious,x,y,obj_enemy,1,0);
if hit == 0 && o {
event_perform(ev_collision, o);
}
Also note that if collision line passes for multiple enemies it isn't guaranteed what object it will apply to
 
Top