(SOLVED)How do you get the id of an instance your colliding with?

Discussion in 'Programming' started by Den, Mar 2, 2017.

  1. Den

    Den Guest

    I'm trying to make each collision with my door objects instances unique when the player collides with it so
    I can turn off the object being solid and pass through it, coz i'm using a collision_line check for my
    enemy's line of sight check and my door object is a child of my obj_solid (which handles all my solids)
    Iv tried instance_find but that just keeps giving me the same instance number for any door the player collides with.
    Is there some way you can just get the specific id of the current door instance i'm colliding with?
     
    Lilabyz likes this.
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,549
    If you are using standard collision events, the colliding instance's ID is other.id.

    If you are using collision checks in the Step event, use instance_place() instead of place_meeting().
    Code:
    var colliding_door_id = instance_place(x, y, obj_door);
    if (colliding_door_id != noone) {
      //...
    }
    PS: Did you follow any tutorials or guides for this? If it was the slightest bit competent, this should have been covered.
     
    K3llyll, Lilabyz and Den like this.
  3. Den

    Den Guest

    Nah It's just my own collision code.
     
  4. Neptune

    Neptune Member

    Joined:
    Jun 21, 2016
    Posts:
    1,031
    instance_position checks a single point for an object-instance -- returns ID if found.

    instance_place checks an area as large as the calling instance's sprite at the desired point for an object-instance -- returns ID if found.

    position_meeting checks a single point for an object instance -- returns 'true' if found.

    place_meeting checks an area as large as the calling instance's sprite at the desired point for an object-instance -- returns 'true' if found.

    So there are only the two kinds of checks (single point or area). It just depends if you need an actual ID return, or a simple boolean return.
     
    Doug, Lilabyz and Den like this.
  5. Den

    Den Guest

    So really I should just change my collision code from place_meeting to instance_place then.
     
  6. Neptune

    Neptune Member

    Joined:
    Jun 21, 2016
    Posts:
    1,031
    Yeah, i think instance_place is a bit taxing to call constantly. Maybe like:
    Code:
    if place_meeting(x,y,o_door)
    {
    var door_inst = instance_place(x,y,o_door);
    }
    Or something similiar?
     
    blandanablandana and Den like this.
  7. Den

    Den Guest

    Yeah that makes sense thanks!
     
  8. Den

    Den Guest

    Just wanna say thank you for the help, it's really appreciated :)
     
    Neptune likes this.

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