When I did this for my game is was built into the basic movement system because I used added vectors to determine movement, so in that case you just add a vector that is move away from near monsters.
at 1:13 is what that movement will look like, theres a horde of rabid raccoon type things.
Unfortunatly this movement system is much much more then a snipit of code...
But a more simple but less perfect / efficient solution could be
Code:
var _spokeList = ds_list_create();
var _radius = 64;
var _spokes = 12;
var _mostOpen = 0;
var _directionToGo = 0;
for(var d = 0; d < _spokes; d++){
var _zombieList = ds_list_create();
var _dir = d * (360/_spokes);
var _xDist = lengthdir_x(_radius, _dir);
var _yDist = lengthdir_y(_radius, _dir);
collision_line_list(x, y, _xDist, _yDist, obj_zombie, false, true, _zombieList,true);
ds_list_add(_spokeList,ds_list_size(_zombieList));
ds_list_destroy(_zombieList);
}
for(var s = 0; s < _spokes; s++){
var _leftSpoke = ds_list_find_value(_spokeList, (s-1)mod(_spokes));
var _spoke = ds_list_find_value(_spokeList,s);
var _rightSpoke = ds_list_find_value(_spokeList, (s+1)mod(_spokes));
var _openness = _leftSpoke + _spoke + _rightSpoke;
if _openness > _mostOpen{
_mostOpen = _openness;
_directionToGo = s * (360/_spokes);
}
}
ds_list_destroy(_spokeList);
you could also use this to avoid walls, and if you make zombies and wall children of the same parent object, you can jsut run it once and they zombies will try and avoide both. Also I wouldn't run this on every zombie every step, maybe every step have 1/5 or 1/10 of the zombies run it. You might have to mess with the radious depending on the size of the sprites and map and how fast everything is going.