1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 Help With Bullet Collision line

Discussion in 'Programming' started by FoufaDjo, Oct 1, 2019.

  1. FoufaDjo

    FoufaDjo Member

    Joined:
    Nov 14, 2018
    Posts:
    8
    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;
    }
     
  2. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    858
    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
     
  3. FoufaDjo

    FoufaDjo Member

    Joined:
    Nov 14, 2018
    Posts:
    8
    Thnx Man It Worked from First Test
     
    Last edited: Oct 1, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice