• 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!

Spacing of Objects in Game

A

AustinLucky

Guest
Code:
var _pushspd = 4;
var _col = instance_place(x,y,obj_zombie)

if(_col){
    var _dist = sign(x - _col.x) * _pushspd
    if(!place_meeting(x + _dist,y,obj_cementwall))
    {
    x += _dist;
This is the code i have in the step event in the zombie obj and it keeps the zombie from colliding with one another although it works it doesnt completely keep them from colliding does anyone have any ideas so that my zombies come in hords and not bunched up??????
 

Attachments

Last edited by a moderator:

zATARA_0

Member
Your current code looks like once they get to a wall they will stack up a lot more, you could have the zombies check in a circle which direction has the most open space and push them that way. Alsodepending on how you are handeling the zombie movement you could encourage them to move away from one another once they get to close.
 
A

AustinLucky

Guest
Your current code looks like once they get to a wall they will stack up a lot more, you could have the zombies check in a circle which direction has the most open space and push them that way. Alsodepending on how you are handeling the zombie movement you could encourage them to move away from one another once they get to close.
I like your idea it seems accurate do you have any preferable code that may show me how to do that.
 

zATARA_0

Member
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.
 
A

AustinLucky

Guest
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.
Thanks so much for the help looking into it !!!
 
Top