[SOLVED] mp_grid_path works differently than expected

Askhat

Member
Hello, i'm trying to make a simple path finding with mp_grid_path function, but it is smth wrong.


I expected that following object will go through center of the nodes. I wrote the minimum path finding code:
- created grid
- added o_wall to forbidden object
- created path
- computed the path with mp_grid_path
- started a path
As you can see, object goes along the curve. Please explain me, what i don't get here.
 
Last edited:

2Dcube

Member
What happens when you align the player object with the grid first?
It's now starting from an off position.

Also you have the cellsize set to the size (in pixels) of the cells in the room right?
 

Askhat

Member
What happens when you align the player object with the grid first?
It's now starting from an off position.

Also you have the cellsize set to the size (in pixels) of the cells in the room right?
Hi, sorry i don't understand what you mean by "align". I show code, it's pretty small.

o_grid create event
Code:
// ----CREATE GRID
var cell_width = 32;
var cell_height = 32;
var hcells = room_width div cell_width;
var vcells = room_height div cell_height;

global.grid = mp_grid_create(0, 0, hcells, vcells, cell_width, cell_height);

// ----ADD WALLS
mp_grid_add_instances(global.grid, o_wall, false);
o_player
Code:
//Global left mouse button
x = (mouse_x div 32)*32+16;
y = (mouse_y div 32)*32+16;
o_path_planner
Code:
//create event
path = path_add();

//end step event
if (mp_grid_path(global.grid, path, x, y, o_player.x, o_player.y, true)){
    path_start(path, 2, path_action_stop, true);
}
 

2Dcube

Member
end step event >
Does this mean the path is started every frame? That could explain the behavior.
The path only needs to be started once.

With "align", I meant that the player is starting at where 4 cells meet, in stead of in the middle of a single cell.
 

Askhat

Member
end step event >
Does this mean the path is started every frame? That could explain the behavior.
The path only needs to be started once.

With "align", I meant that the player is starting at where 4 cells meet, in stead of in the middle of a single cell.
You are right, that was a mistake. Thank you.
It's actually interesting, that you can make path smoother with this)
 
Top