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 How to check for an unobstructed path.

Discussion in 'Programming' started by hans, Nov 9, 2019.

Tags:
  1. hans

    hans Member

    Joined:
    Aug 23, 2018
    Posts:
    25
    Hello, is there a way to see if an instance has an unobstructed path to a specific instance. I'm currently trying to implement an enemy spawner that first checks to see if the enemies it's spawning are able to travel to the player before spawning enemies.
     
  2. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    687
    It depends on how you're doing the path. if it's a straight line you can use something like collision_line.

    Code:
    obstacle = collision_line(fill in the entries)
    Obstacle would hold either an instance ID or noone.
     
  3. hans

    hans Member

    Joined:
    Aug 23, 2018
    Posts:
    25
    Not exactly, i'm trying to see if a path is possible from the spawner object to the player object, and if there is no possible path to not spawn enemies. This would have to be able to circumnavigate a maze like structure.
     
  4. Catastrophe

    Catastrophe Member

    Joined:
    Sep 22, 2019
    Posts:
    106
    Basically, set up an mp_grid, and then use mp_grid_path. If it returns false, you've got no path. An alternate is an A* extension.

    Sidenote: If you're using this method, you may as well use it for your actual pathfinding as well.

    But yeah pathfinding a maze will require a bit of setup like this.
     
    Last edited: Nov 10, 2019 at 10:35 AM

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