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 mb_grid based pathfinding

Discussion in 'Programming' started by The Creator, May 18, 2019.

  1. The Creator

    The Creator Member

    Joined:
    Mar 19, 2019
    Posts:
    10
    In my game I am trying to get the player's recruits to move towards an area where you click. I have the moving towards down but I can't seem to figure out how to create a pathfinder. All the tutorials I have found haven't helped at all, so I am left to ask you guys. How can I make a mb_grid based pathfinding algorithm?
     
  2. the_dude_abides

    the_dude_abides Member

    Joined:
    Jun 23, 2016
    Posts:
    664
    https://www.yoyogames.com/blog/459/dynamic-mp-grids

    That is not about the algorithm, but about how to use mp_grids. The pathfinding is handled by GMS functions, so understanding the inner workings isn't necessary. Personally speaking, I can use them with no problems, but wouldn't have a clue about dissecting how it works. Eventually you might want to make your own, but in the meantime that blog should get you started.
     
  3. The Creator

    The Creator Member

    Joined:
    Mar 19, 2019
    Posts:
    10
    I tried that but it wasn't working with my other project.
    P.S. I changed all the object names to my own.
     
  4. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    685
    Code:
        
    if (state != "MOVING"){
     if (mp_grid_path(obj_main.grid_map, path , x, y, targetX, targetY, true)){
           path_start(path, 4, path_action_stop, true);
           state = "MOVING"
      }else{
           show_message("Path not found");
      }
    }
    
    Here's some code from one of my test projects. It's in the step event of an object that i want to move. You'll need to create a grid and maybe change the variables but... it works and it's basically the same code that's in the link already provided. Maybe you're implementing it wrong, which is why it doesn't work for you.

    Read the whole article and think about what you're doing, whether you want something to run every step or just once and go from there.
     
  5. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    580


    Heres a basic understanding and how to set one up
    I plan on making a new video on this but i hope this helps
     

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