• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM What would cause mp_grid_path() to fail?

  • Thread starter Dennis Ross Tudor Jr
  • Start date
D

Dennis Ross Tudor Jr

Guest
Assumed objects {GameController, Wall, Exit, EnemyParent, TowerMove, TowerParent}

GML:
///GameController create event
globalvar Walking_grid;
Walking_grid = mp_grid_create(64,80,76,76,8,8);
mp_grid_add_instances(Walking_grid,Wall,true);//only walls get added at the start
GML:
///TowerMove Left Pressed event
mp_grid_clear_all(Walking_grid);
mp_grid_add_instances(Walking_grid,Wall,true);
//add the walls back in 
mp_grid_add_instances(Walking_grid, TowerParent, false); 
// add in the towers 
if(instance_exists(EnemyParent)){
   with(EnemyParent){
     recalculate=true;// tell each enemy to recalculate their path
   }
 }
GML:
///EnemyParent create event
if(x<200){ //spawn from left
   my_exit=instance_nearest(x+500,y,Exit);
}else{ // spawn from top
   my_exit=instance_nearest(x,y+500,Exit);
}
move_speed=2; 
recalculate=false; 
walking_path=path_add(); 
if(mp_grid_path(Walking_grid,walking_path,x,y,my_exit.x,my_exit.y,true)){
     //for some reason even in an empty room it fails to find a path
   path_start(walking_path,move_speed,path_action_stop,1);
}
GML:
///EnemyParent step event 
if(recalculate){
   recalculate=false;
   path_delete(walking_path);
   walking_path=path_add();
   if(mp_grid_path(Walking_grid,walking_path,x,y,my_exit.x,my_exit.y,true)){
       //for some reason even with just one TowerParent in the room it fails
       //to find a path
     path_start(walking_path,move_speed,path_action_stop,1);
   }
}
So that's the setup for the AI to traverse the map and find it's way to it's Exit. The problem is the AI doesn't move at all. When I debug it and step through the EnemyParent's create event or step event where it tries to find a path, it fails to find one. The room is empty except for (4) Walls that keep the AI in bounds, along with (2) Entrances and (2) Exits in a crisscross pattern. However even when the room is empty except for the Walls, Entrances and Exits the AI still fails in finding a path.

NOTE:

  • TowerMove is a child of TowerParent and does an instance_change() into it's appropriate tower.
  • None of the objects are solid.
as you can see from the pic below the EnemyParent does not find a path. The only blocking grid cells are the red walls. The EnemyParent's exit is across the field on the other side. (think tabletop td)

path issue.png
 
D

Dennis Ross Tudor Jr

Guest
After trying a few things out I witnessed that when I moved the Exit object outside of the grid and changed the target_x and target_y to a static location in the grid, the AI could find a path. Why would the Exit object cause the AI to fail in finding a path? It wasn't part of the instances that I wanted the AI to avoid.

EDIT: I kept the goal_x and the goal_y as static locations in the room but moved the Exit object back into the grid and the AI still could find the path. Why would using my_exit.x, and my_exit.y instead of static locations in the room cause mp_grid_path() to fail? When debugged they were the same value.

GML:
goal_x=656;
goal_y=384;

move_speed=2;

walking_path=path_add();
recalculate=false;

if(mp_grid_path(Walking_grid,walking_path,x,y,goal_x,goal_y,true)){ //changed to goal_x and goal_y - mno
  show_debug_message(string(id)+": "+object_get_name(object_index)+":Create Event: - found a path");
  path_start(walking_path,move_speed,path_action_stop,1);
}else{
  show_debug_message(string(id)+": "+object_get_name(object_index)+":Create Event: - did not find a path");
}
Untitled.png
 
Last edited by a moderator:
Top