GML Mass collision between objects

M

Mark Lubetzki

Guest
Hello Community,
I struggle at the collision between for example a horde zombies.
If i have like 15 objects on the "same" spot, they stack inside each other and
can't move anymore. Have anyone expierience with so many collisions at once ?
It is great if they are "slide" off each other.

Thank you for any help.
 

Brodie

Member
Hey mark, I haven't tested it, but you could try something like this in the step event of the zombie (here oZombie):

var collidingZombie = collision_circle(x, y, sprite_width/2, oZombie, false, true);
if instance_exists(collidingZombie)
{
x = x + lengthdir_x(1, point_direction(collidingZombie.x, collidingZombie.y, x, y));
y = y + lengthdir_y(1, point_direction(collidingZombie.x, collidingZombie.y, x, y));
}

The code should check for a collision with another Zombie, and if one is found, push itself away by one pixel each step.
 

Bentley

Member
Edit: Just read Brodie's answer (above mine). That's probably what you're looking for.

You could try to keep them from getting to the same position in the first place. If it's a grid game, maybe I can help you. Let's say every zombie occupies a square. When a zombie wants to move from square A to square B, do a few things:

If there's not an instance of obj_reserved on square B and there's not a zombie on square B:
1. Place an instance of obj_reserved on square B
2. Move there.
3. Destroy that instance of obj_reserved.

This probably won't help if you're going for a "horde" look where they swarm all over each other. But I thought I'd post just in case it does help.
 
M

Mark Lubetzki

Guest
Thank both of you.
This would end in a very woobly mess... i need a very solid "horde"... i have no idea
 
Top