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

2018/3/1

How to get enemy to follow object and attack it?

IlikeThePrequels IlikeThePrequels

2018/3/1

#
I want to get my enemy to follow and attack a stationary object. My follow beehive method public void followBeehive() { turnTowards(150,500); Actor beehive = (Actor) getOneIntersectingObject(Beehive.class); if(beehive !=null) { getWorld().removeObject(beehive); } } My attack beehive method public void attackBeehive() { if(!getObjectsinRange(500, Beehive.class).isEmpty()) { Actor beehive=(Actor) getObjectsinRange(200, Player.class).get(0); if(beehive !=null) { followBeehive(); } } } I'm also getting errors saying cannot find symbol - method GetObjectsinRange(int,java.lang.Class<Beehive>). Sorry, I'm very new to greenfoot. Please help me.
danpost danpost

2018/3/1

#
Should be '...InRange' with a capital 'I'.
IlikeThePrequels IlikeThePrequels

2018/3/1

#
Danpost I did that. My enemies are randomly spawning but trying to move towards the object off screen instead of moving directly towards it.
danpost danpost

2018/3/1

#
Please be more detailed. Give speed, direction relative to object, how far off object is missed, etc. -- especially code used.
You need to login to post a reply.