hiding behind tiles

Discussion in 'Programming' started by stinger, Jun 10, 2019.

  1. stinger

    stinger Member

    Joined:
    Aug 7, 2016
    Posts:
    10
    Hi. I am trying to go from objects to tiles in my room. I had code in the past that would essentially hide the player from an enemy if they were behind an object...

    // Is the player in the clear from this enemy or is the player behind something...
    if (collision_line(obj_player_v2.x, obj_player_v2.y,x,y,obj_box,0,1)))...

    Now that I've gone to tile sets for better performance I don't know what the equivalent is to determine if
    there is a tile between an enemy object and the player.

    Does anyone have a solution?

    Cheers,
    Stinger
     
  2. zATARA_0

    zATARA_0 Member

    Joined:
    Apr 10, 2019
    Posts:
    40
    If you know what layer the object you would hide behind is on, then you can write your own version of collision line for tiles.
    Basically the arguments would be start x, start y, end x, end y, layer, dist between checks

    var _dist = point_distance(startX,startY,endX,endY);
    var _dir = point_direction(startX,startY,endX,endY);

    for(var d = 0; d < _dist; d+=distBetweenChecks){
    // what code you use here depends on if you have gms 2 or 1.4, since they handle tiles very differently, this is the gms 2 version
    var _lenX = lengthdir_x(d,_dir);
    var _lenY = lengthdir_y(d,_dir);
    var _tile = tilemap_get_at_pixel( layer, x+lenX, y+lenY);
    if _tile != -1{
    return _tile;
    }
    }
     

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