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

2013/5/11

Getting Enemies to Follow the Player

cecarson cecarson

2013/5/11

#
Hey guys. cecarson here. You may have seen my series called Paintball. Now I have a problem with Paintball 2: Zombies. I find it kind of boring that the zombies only move in one direction. I want to be able to make the zombies follow the player. Please tell me how I can make that possible.
Avik Avik

2013/5/11

#
public void act() { moveIt(); followHuman(); RandMove(); } public void moveIt() { move(2); if(atWorldEdge()) { turn(5); } } public void RandMove() { if(Greenfoot.getRandomNumber(100)>20) { turn(Greenfoot.getRandomNumber(20)-10); } } public void followHuman() { String target; getObjectsInRange(400,Survivor.class); int targetX = getX(); int targetY = getY(); } just change the human to what ever you have called it.
You need to login to post a reply.