OFFICIAL Tech Blog: Dynamic MP Grids

Nocturne

Friendly Tyrant
Forum Staff
Admin
https://www.yoyogames.com/blog/459/dynamic-mp-grids



If you've ever had to make any type of enemy movement in a game (especially a top down game) the chances are that you've had a look at - or used - the Motion Planning Functions, specifically MP Grids. On the surface, MP grids may seem a great solution for finding a way through a predefined maze, but are too rigid to be used in other circumstances, since, as the name implies, they "lock" movement to a grid. Well, in today's tech blog, I'm here to tell you that that isn't true, and you can use MP grids to create complex-appearing and dynamic AI with just a few lines of code...
https://www.yoyogames.com/blog/459/dynamic-mp-grids
 

GMWolf

aka fel666
A great read for those looking for more from the MP grid functions!
One issue you may run into is that when the path is drastically changed, the pos variable may refer to a point that is quite far away from the current location, and the AI may not be able to find its way to it. In that case one solution is to find the closest point on the path before continuing.
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
One issue you may run into is that when the path is drastically changed, the pos variable may refer to a point that is quite far away from the current location, and the AI may not be able to find its way to it. In that case I suggest finding the closest point on the path before continuing.
There are a few issues like that with the system... Like when you place a block in the same position as the AI object, it'll get"stuck"... But the point is that after going through the article, you should be able to solve those issues yourself (we hope!)!

:)
 

Miradur

Member
Great tutorial and always nice to see how you can improve self.
My wish for the next tutorial would be a deep-sort routine with tile layers :)
(Maybe with collision and alpha for the player when he is behind the tiles).

Miradur
 
O

OrangeBit

Guest
It gave me a YYZ file. Not supported with Studio 1.4?
 
S

Smarty

Guest
Nice write-up @Nocturne. I've experimented long time ago with the grid-based path finding and I think it's important to emphasize that the grid should be a miniature representation of the room. The smaller the grid the faster the pathfinding algorithms.

Not related to the article, but I think the one lacking feature of pathfinding in GMS is that it is limited to just go and no-go areas. It is not possible to indicate areas that have a (speed) penalty to cross them. For example, asphalt terrain vs grassland terrain - pathfinding should preferably go for the fastest route between A and B, and opt for ' slower' terrain only if necessary. Grid values would be -1 for impassable terrain, and 0 to any value higher up to indicate the penalty.
 
Last edited by a moderator:

GMWolf

aka fel666
Nice write-up @Nocturne. I've experimented log time ago with the grid-based path finding and I think it's important to emphasize that the grid should be a miniature representation of the room. The smaller the grid the faster the pathfinding algorithms.

Not related to the article, but I think the one lacking feature of pathfinding in GMS is that it is limited to just go and no-go areas. It is not possible to indicate areas that have a (speed) penalty to cross them. For example, asphalt terrain vs grassland terrain - pathfinding should preferably go for the fastest route between A and B, and opt for ' slower' terrain only if necessary. Grid values would be -1 for impassable terrain, and 0 to any value higher up to indicate the penalty.
also, would be nice to have more than just a*. For a lot of games, its often useful to keep the annotated graph around.
For instance, you can do Dijktras with the target as source, and end up with a single data structure that can easily be used to reach the source from any point on the graph. Very usefull for, lets say, a zombie game.
You can do the opposite, compute all of the reachable nodes from a source. Very useful when for AI (Select the best reachable destination. Could even use to check that destination is not reachable by enemies, etc), or to show where the player can move to in a turn based game.
 
A

Andy

Guest
I have been playing with path-finding and MP grids, so this article is timely. :)
 
Top