# How to make a path without collisions regardless of the size of the enemy/grid?

I am making a game where I have a player and enemies that depending on the distance, follow the player.

For enemies to follow the player, the map was marked with a grid. When the player approaches the enemy, the enemy creates a path to the player, ignoring the walls (obj_Block).

Code - Creation grid (obj_ADM):

global.grid=mp_grid_create(0,0,celHor,celVer,celLar,celAlt);

mp_grid_add_instances(global.grid,obj_Block,false);


Code - Creation path (obj_Enemy):

xPlayer=(obj_Player.x div obj_ADM.celLar)*obj_ADM.celLar+obj_ADM.celLar/2;
yPlayer=(obj_Player.y div obj_ADM.celAlt)*obj_ADM.celAlt+obj_ADM.celAlt/2;

if(mp_grid_path(global.grid,caminho,x,y,xPlayer,yPlayer,1)){
path_start(caminho,velocidade,path_action_stop,false);
}

• The grid is 20x20.

• The size of the room tiles division is also 20x20:

• The obj_Block size is also 20x20.

• But the size of the enemy is 32x32.

So, something similar to the image below happens:

• Purple Square => enemy
• Black Squares => wall

The enemy ends up going through a part of the wall while chasing the player.

This is obviously because of the different size of the grid and the enemy. Because I did a test with the enemy with the size of 20x20 and it worked perfectly.

I changed the size of the grid (which creates the path) to 32x32, and it turned out that instead of crossing the wall, the enemy ends up being well away from the walls (in some places on the map):

I would like to know how to do so that none of these situations happens. Regardless of the size of the enemy.

Video I used to make the code:

https://www.youtube.com/watch?v=LUw78Tk70bM&