Quick answer: Either set allowdiag = false on mp_grid_path to disable diagonals entirely, or grow walls by half a cell so the diagonal cell is blocked as well. mp_grid’s diagonal logic doesn’t check the cardinal neighbors of a diagonal step.
Your enemy AI uses mp_grid_path with allowdiag enabled. It produces a path that diagonally clips a wall corner, sliding through stone. Visually wrong, gameplay-breakable.
The Symptom
AI walks diagonally through corners where the geometry has a wall on the cardinal sides. The diagonal cell itself is open, but the path shouldn’t use it because the entity can’t physically squeeze through.
What Causes This
mp_grid_path with allowdiag = true allows diagonal transitions if the destination cell is open. It doesn’t check that both adjacent cardinal cells are also open — so a diagonal between two walls (NW open, N blocked, W blocked) is considered legal.
The Fix
Option 1: Disable diagonals. Cleanest if your art style permits cardinal-only movement.
path_found = mp_grid_path(grid, path, x, y, target_x, target_y, false); // allowdiag = false
Option 2: Pad walls. When you build the grid, add wall rectangles slightly larger than the actual wall. The diagonal cell adjacent to a wall corner becomes blocked.
var cell_w = 32;
var cell_h = 32;
grid = mp_grid_create(0, 0, room_width div cell_w, room_height div cell_h, cell_w, cell_h);
with (obj_wall) {
mp_grid_add_rectangle(other.grid,
bbox_left - 8,
bbox_top - 8,
bbox_right + 8,
bbox_bottom+ 8);
}
The +/-8 padding around each wall blocks the diagonal cell touching the corner. Paths route around. Tune the pad size to match your sprite size; too big and you lose passable corridors.
Custom A* Alternative
If you need fine control, write A* with explicit corner-cut prevention:
// Allow NW move only if N or W is also open
if (dir_is_diagonal) {
if (!cell_open(x, y - 1) || !cell_open(x - 1, y))
continue; // no corner cut
}
Verifying
Spawn an enemy near a wall corner with a target across the wall. The path debug overlay should route around the corner, not through it. mp_grid_draw shows the grid; verify diagonal cells next to walls are blocked when padded.
“Disable diagonals or pad the walls. mp_grid stops cheating.”
Related Issues
For surface lost on resize, see surface lost. For instance deactivate, see deactivate region.
Pad or disallow. Paths respect walls.