artificial intelligence - Game Maker: Studio - Make objects avoid other instances of same object with A* pathfinding -



artificial intelligence - Game Maker: Studio - Make objects avoid other instances of same object with A* pathfinding -

i have game there multiple enemies must chase single player. have pathfinding set using gml a* pathfinding mp_grid , path. however, these enemies can walk on top of each other when seeking player. prepare this, told path ignore enemies mp_grid_add_instances, stop moving altogether because see obstacles, trapping within bounding box. there way can add together "all other enemies self" mp_grid_add_instances?

here's grid creation code (in controls class initializing variables):

global.zombie_ai_grid = mp_grid_create(0, 0, room_width / 50, (room_height - sp_dashboard.sprite_height) / 50, 50, 50); mp_grid_add_instances(global.zombie_ai_grid, obj_obstacle, false);

this path initialization code (in zombie class):

path = path_add(); alarm[0] = 5;

this path creation code in alarm 0 (path updates every 2 seconds):

mp_grid_path(global.zombie_ai_grid, path, x, y, nearest.x, nearest.y, true); path_set_kind(path, 1); path_set_precision(path, 8); path_end(); path_start(path, max_speed, 0, true); alarm[0] = room_speed * 2;

you need clear cell each enemy before calculating path , set after. this:

mp_grid_clear_cell(global.zombie_ai_grid, x div cell_size, y div cell_size); mp_grid_path(global.zombie_ai_grid, path, x, y, nearest.x, nearest.y, true); mp_grid_add_cell(global.zombie_ai_grid, x div cell_size, y div cell_size);

but note 2 enemies must not have collision (located in same cell), otherwise enemy not marked obstacle.

other way:

mp_grid_clear_all(global.zombie_ai_grid); (obj_obstacle) { if (id != other.id) { mp_grid_add_instances(global.zombie_ai_grid, id, false); } }

if work slowly, need create queue , every step need calculate path few zombies.

artificial-intelligence path-finding game-maker

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -