© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
B. TyersGameMaker Fundamentalshttps://doi.org/10.1007/978-1-4842-8713-2_28

28. MP Grids

Ben Tyers1  
(1)
Worthing, West Sussex, UK
 

MP Grids allow you to create dynamic paths on the fly that will find a path between two points, avoiding instances along the way.

Great for
  • Enemies searching for the player.

  • Automated instances that search for food or supplies.

Setting a Grid

First you can set the grid size, depending on how your room is set up, for example:
global.grid=mp_grid_create(0,0,room_width / 64, room_height / 64, 64, 64);

which would set a grid size of 64.

You can set which instances need to be avoided by adding them to the grid:
mp_grid_add_instances(global.grid,obj_wall,true); ...

Get GameMaker Fundamentals: Learn GML Programming to Start Making Amazing Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.