- Title: Basic and Advanced MP_Grid Use
- Description: Four files (Very Basic, Basic, Advanced and Other) that use mp_grid and path-finding
- GM Version: These were done on GM7. If anyone wishes to convert them to GM6 then feel free to PM me and I will include a link in this post.
- Registered: Yes
- File Type: 4 .gmk files
- File Size: each one approx 0.04mb
- File Link (1):

- File Link (2):

- File Link (3):

- File Link (4):

Additional Info
After having helped a few people with AI and seen more than a few tutorials on the theme, I decided to add my grain of sand... Here I have three different files, all related to the GM mp_grid function and demonstrating different ways of using and controlling the paths this can generate... It must be noted that to fully understand these examples (except the Very Basic) an intermediate knowledge of GML is needed!!!
File One... Very Basic MP_Grid Example.
This example has one object that travels from a start point to a finish point and is ideal for Tower Defense style games. The path is created once at the start, but if you press the right mouse button a new wall object is created and the path is adapted to avoid it. This example is recommended for beginners as it is very simple.
All the code in this example is heavily commented!!!
File Two... Basic MP_Grid Example.
This example has a basic AI object with two "states", Patrol and Alert. In patrol it follows a node based path around a room. The path is only generated when the object comes in contact with a patrol node. The AI object and patrol nodes have code in their room editor creation event, and to see it go to the room editor and "control+right_click" the object (For more information on this, see This Post by Chronic). In the example, if you press the left mouse button the AI changes to alert mode and starts moving randomly between alert nodes, again using mp_grid to calculate the paths. There is also the option to place walls dynamically in the way of the AI with the right mouse button, and the AI will automatically recalculate the path. Pressing enter resets the room...
All the code in this example is heavily commented!!!
File Three... Advanced MP_Grid Example.
This is the same as the above, but now has two AI objects, each with it´s own patrol route and four "states"... Patrol, Alert, Spotted, and Follow. There is also a player object and again, if you press the left mouse button the AI changes to alert mode, the right mouse button places and obstacle and enter resets the room. There is also a Player object controlled by the cursor keys.
There are NO comments in this example and it is recommended that you check the first one out and make sure you understand it before downloading this!!!!
File Four... Other MP_Grid Example.
This is an example based off of a file I helped someone with and is used to demonstrate how to dynamically create paths on a step by step basis. Move the mouse around to change the path and see how the 'ship' reacts. When there is no path the 'ship' calculates the nearest point to where the mouse is without a blocking object and moves there. (See post #10 for an edit to stop the ship "bouncing" when there is no path...)
This example has the path finding content commented and is fairly basic and easy to follow.
I hope that these files can be of help to anyone wishing to use and understand the mp_grip and path functions provided by GM. They are by no means perfect, (but then they are not meant to be!) and the code cannot be directly "cut and pasted" into your work. I have provided them as I have been working extensively on this for my game and feel that they may be of interest and learned from...
Please comment, and if you do use anything here, no credit is necessary (but apreciated!).











