Grid pathfinding
Finds the shortest route across a grid of tiles, around walls and through the cheapest ground. A character can prefer a road over a swamp, and many enemies can chase one player without slowing the game down.
When you need it
For tile-based games: enemies that chase you, units you click to move, tower defense, turn-based tactics, or checking that a generated map can be crossed at all.
Say this to your AI
Use the grid pathfinding from Spielerando so my enemies find the shortest way to the player, around walls, and avoid walking through water.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
Settings
- moves (8): 8 allows diagonal steps, 4 does not.
- corners (avoid): "avoid" never cuts past a wall's corner, so characters do not clip through it. "cut" lets them.
Your AI gets the code
The finished code and math come through the Spielerando connection, so your AI can use them right away. Connect your AI
Common questions
how do i make enemies find a path to the player
Treat the map as a grid of tiles and search outwards from the enemy, always trying the most promising tile next, until the player's tile is reached. The recipe does that and gives you the route tile by tile.
how do i make a character avoid water but still cross it if needed
Give water a higher cost per step instead of blocking it. The route then goes around when that is cheaper and through when it is not.
my game gets slow with many enemies pathfinding
When they all head for one target, work out the way to it once from every tile. Each enemy then just reads its next step, however many there are.