• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 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