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

2014/3/26

Objects overlapping

Azurelle Azurelle

2014/3/26

#
Hello, im working in a zombie survival game in wich the zombies chase the player. I want to stop the zombies from overlapping themselves but i need help. Here is the code of my Zombie class:
    public void act() 
    {
        chasePlayer();
        eatPlayer();
    }
    
    public void chasePlayer()
    {
        turnTowards(Player.playerX, Player.playerY);
        move(1);
    }
    
    public void eatPlayer()
    {
        Actor player;
        player = getOneIntersectingObject(Player.class);
        if(player != null)
        {
            getWorld().removeObject(player);
            Player.Dead = true;
        }
    }
Azurelle Azurelle

2014/3/27

#
can someone help me? im stuck in this :/
danpost danpost

2014/3/27

#
If you do not want them to overlap, then how do you want them to move (if at all) when another zombie is close by? Would this be a TDS (top-down shooter) type game?
Azurelle Azurelle

2014/3/27

#
Yes its a top-down shooter type game. When the zombies chase me , they overlap and it visually looks that there is only one zombie. I need help with this :]
danpost danpost

2014/3/27

#
So, it is ok for them to overlap, just not completely? What behavior would you like them to have when they would otherwise overlap?
Azurelle Azurelle

2014/3/27

#
Basically i want them to block each other .
danpost danpost

2014/3/28

#
Then change your chasePlayer method to this:
public void chasePlayer()
{
    turnTowards(Player.playerX, Player.playerY);
    move(1);
    if (!getIntersectingObjects(Zombie.class).isEmpty()) move(-1); // add this line
}
Azurelle Azurelle

2014/3/28

#
Thank you, but adding this line makes the zombies stop when they colide, i need them to continue to chase the player. But blocking each other so the zombies dont overlap.
Azurelle Azurelle

2014/3/30

#
still need help with this , someone can help me?
BatteryBot BatteryBot

2016/3/2

#
You could do something like making the zombies solid to each other... just an idea....
You need to login to post a reply.