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

2017/3/8

How can the second actor to follow the primary actor

H3ater H3ater

2017/3/8

#
Hello. I try to make an simpla game, with this actors, Bee, Fly, Spider. In this game you are the Bee and you need to catch all flys but withcout touch the spiders. For a moment i make this spiders to moves and turns completly random. But i want all the spiders to follow the Bee with random turns. How can i make this ?
Nosson1459 Nosson1459

2017/3/8

#
That's a very good question, because if you're following someone then your turns aren't random if your turns are random then you might end up going in a different direction then whatever it is you are following. You can have one actor follow another but I don't know what you mean by "follow the Bee with random turns".
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import greenfoot.*;
 
public class Bee extends Actor
{
    private Spider spider = new Spider(); // fit name and constructor to your scenario
 
    /**
     *
     */
    @Override
    public void act()
    {
        spider.setRotation(getRotation());
        // now the spider will always be facing the same direction as the bee,
        // but if they are too far apart or moving at different speeds then the spider might not really end up following the bee
        // this is if they are both moving with the 'move' method
    }
}
You need to login to post a reply.