• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

SOLVED mp_grid_path not being followed, object flies off or doesn't return to passive path

I have an mp_grid setup that works during the aggro state just fine, but the passive state only works when I add && (path_index == -1) to the if (mp_grid_path(...)) statement. However, this causes the object to not return to its passive path once the aggro state is left. Without the && (path_index == -1), the object just flies off, ignoring the grid entirely, like this:



Create:
GML:
chase = false;
pathPassive = 0;
pathAggro = 0;

global.mpgrid = mp_grid_create(0, 0, room_width / 8, room_height /8, 8, 8);

var _colMap = layer_tilemap_get_id(layer_get_id("col"));
var _w = room_width / TILE_SIZE;
var _h = room_height / TILE_SIZE;

//Loop through x and y to find tiles
for (var i = 0; i < _w; i++;) {
    for (var j = 0; j < _h; j++;) {
      var _tile = tilemap_get_at_pixel(_colMap, i * TILE_SIZE, j * TILE_SIZE);
      if (_tile == 1) {
        mp_grid_add_cell(global.mpgrid, i, j);
      }
    }
}
Step:
GML:
//Checks for collision with player in a circle radius and initiates chase
if (collision_circle(x, y, dr, obj_player, false, false))
    {
        chase = true;       
    }
    
//Hiding & line of sight ends the chase
if (global.Hide) && collision_line(x, y, obj_player.x, obj_player.y, obj_player, false, false))
    {
        chase = false;
    }

if (chase == true)
{

    //If the path doesn't exist, create it.
    if(!path_exists(pathAggro)) pathAggro = path_add();
    
    //With each step, the grid path is drawn & checks that a path isn't currently being followed
    if (mp_grid_path(global.mpgrid, pathAggro, x, y, obj_player.x, obj_player.y, 0))
    {
        path_start(pathAggro, global.gamePathSpeed, path_action_stop, 0);
    }
}
else
{
    
    //If the path doesn't exist, create it.
    if(!path_exists(pathPassive)) pathPassive = path_add();
    
    //With each step, the grid path is drawn & checks that a path isn't currently being followed
    //Without path_index == -1, the path is drawn every frame and the movement doesn't repeat in reverse
    if (mp_grid_path(global.mpgrid, pathPassive, xstart, ystart, xTo, yTo, 0))// && (path_index == -1))
    {
        path_start(pathPassive, global.gamePathSpeed, path_action_reverse, 0);
        show_debug_message("Path found");
    } else show_debug_message("Path not found");
        
}
 
Update: It seems as if it's following the path relative to itself, instead of the absolute path originally drawn at the start of the room. Changing the path_start's last value to 1 didn't seem to do anything.

EDIT: NVM, just needed to recompile. That was the issue.
 
Last edited:
Top