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

2016/3/5

How do i get an object to follow another?

Stratmoss Stratmoss

2016/3/5

#
I have seen the other questions (and watched a tutorial) but none of them work for me. I want follow_ant to follow bread.
public class follow_ant extends Actor
{
    int test = 0;

    public void act() 
    {
        move(2);
        bread player = (bread) getWorld().getObjects(bread.class).get(0);
        turnTowards(player);
    }
}
I found this code on another question. The bread moves with the arrow keys. What am i doing wrong. Thanks
Super_Hippo Super_Hippo

2016/3/5

#
The 'turnTowards' methods needs two int parameters and not an object. Change line 9 to:
turnTowards(player.getX(), player.getY());
You need to login to post a reply.