This site requires JavaScript, please enable it in your browser!
Greenfoot back
iminblue
iminblue wrote ...

2019/2/10

Enemy Collision

iminblue iminblue

2019/2/10

#
Ok so I made some enemies that track the player and follow him but they eventually stack up . How can I make them 'collide' with each other so it's easier to spot every single one of them?
danpost danpost

2019/2/10

#
Same way you prevent a player from passing through walls, ground and platforms -- move, check for collision and, if hitting something, move back.
iminblue iminblue

2019/2/12

#
Ok but when I go through the list containing all of the enemies I get to a point where 2 of them always block into each other and don't move . I guess it's because they firstly check wheter or not they intersect with the first enemy ever created in the world that is therefore the first in the list ?
danpost danpost

2019/2/12

#
iminblue wrote...
Ok but when I go through the list containing all of the enemies I get to a point where 2 of them always block into each other and don't move . I guess it's because they firstly check wheter or not they intersect with the first enemy ever created in the world that is therefore the first in the list ?
I am not sure about your deduction. However, I can say it would end up to be like a traffic jam, where they will not move due to congestion.
iminblue iminblue

2019/2/12

#
danpost wrote...
iminblue wrote...
Ok but when I go through the list containing all of the enemies I get to a point where 2 of them always block into each other and don't move . I guess it's because they firstly check wheter or not they intersect with the first enemy ever created in the world that is therefore the first in the list ?
I am not sure about your deduction. However, I can say it would end up to be like a traffic jam, where they will not move due to congestion.
public void move()
    {   Actor player =getWorld().getObjects(Player.class).get(0); 
        wall = getOneObjectAtOffset(0,-10,Wall1.class);
        if (wall==null )
        setLocation (getX() + direction*speed,getY()+dy*speed);
        java.util.List enemies = getWorld().getObjects(Enemy.class);
        for (Object obj : enemies)
               { enemy = (Enemy)obj;
                if (enemy!=this && intersects(enemy)) setLocation (getX() - direction*speed,getY()-dy*speed);}
    }
They end up in a traffic jam that's the problem .
danpost danpost

2019/2/12

#
iminblue wrote...
They end up in a traffic jam that's the problem .
Well, they will be either on top of each other (fully or partially) or not. You cannot have it any other way.
You need to login to post a reply.