

Mp_grid_define_path(obj_Start.x, obj_Start.y, obj_Finish.x, obj_Finish.y) Mp_grid_add_instances(global.ai_grid, obj_wall, false) With the Create event open, add the following code: global.ai_grid = mp_grid_create(0, 0, room_width / 64, room_height / 64, 64, 64) In general, it's good practice when using MP grids to only ever create one and have all instances access that, since creating and using MP grids is a fairly processor intensive task. Both the grid and the path will have their unique ID's stored in a global scope variable - we use global variables since we only need one single path and one grid for all instances to use in this project.

Here, apart from creating our MP grid, we will also make a single path resource too.

To get started, we'll first need to create our MP grid resource, so open up the object "obj_Control" and open the Create Event code block now. You then assign this path resource to an instance and it will look to the player like the instance is displaying "intelligence" as it neatly avoids obstacles while following the path. This grid is then used by another mp_* function to create a unique path resource that will try to go around those squares flagged as "occupied" and go through those ones that are not. Which is where the MP grid comes into play!įor those that maybe haven't dipped their toes into this water yet, an MP grid is a "motion planning grid", and all it does is section up a room into individual grid "squares", and each of these squares can then be flagged as "occupied" or not. We need to spice things up a bit and have our enemy change direction and react dynamically to things that the player does, and in this case we are going to have it change direction and avoid walls that the player adds into the room while playing.
