D
Dennis Ross Tudor Jr
Guest
Assumed objects {GameController, Wall, Exit, EnemyParent, TowerMove, TowerParent}
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:
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);
}
}
NOTE:
- TowerMove is a child of TowerParent and does an instance_change() into it's appropriate tower.
- None of the objects are solid.