1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 [SOLVED!] Pathfinding stop when surrounded

Discussion in 'Programming' started by DragonRod342, Dec 2, 2019.

  1. DragonRod342

    DragonRod342 Member

    Joined:
    Dec 2, 2019
    Posts:
    1
    Hi everyone o/

    I'm coding a top down game where enemies follow the player if they're close enough to it. I'm using this code:
    this works pretty fine, but when an enemy with this code is surrounded by walls and have no possible path to follow, it just disappears! My game'll have some places, like fences/walls where some enemies'll be placed inside.
    Like this:
    upload_2019-12-1_21-54-51.png

    How could I define, like, if this enemy is surrounded by the obj_Solid (which is my wall obj.), it ignores the Target and sets the "IsFollowing" variable to false?
     
  2. TailBit

    TailBit Member

    Joined:
    Oct 16, 2019
    Posts:
    76
    from the 10th line
    Code:
    // mp_grid_add_instances(path,obj_Solid,true) // this line tries to treat the path as a grid, and you have already added the walls to the grid
    if( mp_grid_path(grid,path,x,y,Target.x,Target.y,true) ){ // this returns if the path can be completed or not
        path_start(path,Spd,"",true) // "" should be: path_action_stop
    }else{
        IsFollowing = false
    }
     

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