In the game I'm trying to make, I have 2 enemies that go from their starting x and y to a blue block, then back to their starting x and y, then pick a new blue block to go to and repeat the cycle. This works pretty great 8/10 times. However, as I've been watching the enemies start their routes I've noticed 2 peculiar I guess edge cases that arise from time to time when I run the game.
The first one is they will favor one blue block over the others, and typically the two enemies will favor the same blue block. It's very interesting to see happen after a series of runs, to be honest. One enemy will seem to just pick one block more and more until eventually 9/10 times its the only block it goes to, and the other enemy eventually follows suit. I have no idea why this is, or why it doesn't happen every time, but typically it happens after I run the game for a while. It's almost as if the randomized system I have for choosing the blocks stops being random at a certain point.
The second case is just general malfunctions. Sometimes one enemy will stop moving entirely, or they'll never begin to move at all and stay at their starting x and y. This is less common than the first case, and typically only happens to one of the enemies and not both. It is still problematic though since I don't want my player to be replaying the level and it suddenly does not work.
The code I have to shuffle the blocks, or in this case I call the DropBoxes, and the pathfinding is in a finite state machine. First I create a list in the create event of a present invisible game object. I also randomize the seed
Then, I have the enemies start in their first state where they shuffle the list of dropboxes, assign the first value of the list to a variable the office workers use, remove said value from the list so that no other office worker can use the same dropbox and change the state of the enemy to a pathfinding state for the chosen dropbox:
This pathfinding state switches from two cases, one that starts the path to the dropbox and the other to return to the x, y. Notice I return the dropbox value to the list at the end of the route to the dropbox.
And it just goes round and round. Does anyone have any insights as to why this is happening and how I can improve the system?
The first one is they will favor one blue block over the others, and typically the two enemies will favor the same blue block. It's very interesting to see happen after a series of runs, to be honest. One enemy will seem to just pick one block more and more until eventually 9/10 times its the only block it goes to, and the other enemy eventually follows suit. I have no idea why this is, or why it doesn't happen every time, but typically it happens after I run the game for a while. It's almost as if the randomized system I have for choosing the blocks stops being random at a certain point.
The second case is just general malfunctions. Sometimes one enemy will stop moving entirely, or they'll never begin to move at all and stay at their starting x and y. This is less common than the first case, and typically only happens to one of the enemies and not both. It is still problematic though since I don't want my player to be replaying the level and it suddenly does not work.
The code I have to shuffle the blocks, or in this case I call the DropBoxes, and the pathfinding is in a finite state machine. First I create a list in the create event of a present invisible game object. I also randomize the seed
GML:
randomize();
global.db_List = ds_list_create();
ds_list_add(global.db_List,oDB1,oDB2,oDB3,oDB4);
GML:
function DropBoxShuffle(){
ds_list_shuffle(global.db_List);
myDropBox = ds_list_find_value(global.db_List, 0);
ds_list_delete(global.db_List,myDropBox);
state = ENEMYSTATE.WANDER;
}
GML:
/// Have office worker go from objective then back to desk
switch (route) {
// path route to the drop box
case 1:
pathDB = path_add();
dX = (myDropBox.x div 16)*16+8;
dY = (myDropBox.y div 16)*16+8;
if (mp_grid_path(global.grid, pathDB, x, y, dX, dY, true))
{
path_start(pathDB, 1, path_action_stop, false);
}
// Do something once the path has been complete
if (path_position == 1)
{
route = 2;
ds_list_add(global.db_List,myDropBox);
path_delete(pathDB);
}
break;
// Path route to back to the desk once it reaches its destination
case 2:
pathRe = path_add();
if (mp_grid_path(global.grid, pathRe, x, y, xTo, yTo, true))
{
path_start(pathRe, 1, path_action_stop, false);
}
if (path_position == 1)
{
route = 1;
state = ENEMYSTATE.SHUFFLE;
path_delete(pathRe);
}
break;
}
Last edited: