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

2012/4/5

Move around an actor?

nooby123 nooby123

2012/4/5

#
Hi, I'm trying to make an actor(let's call it actor a) that move around in a circle around another actor(actor b), even while actor b is moving. All I've got is this :
public act() {
    move(5);
    setRotation(getRotation() + 10);
}
But it keeps spinning in the same place over and over again even when actor b is moving. Help!
danpost danpost

2012/4/5

#
You could set the location of actor a to that of actor b, and then move(n) away; where n is the distance from actor b you want actor a to stay. Each time adjusting the rotation by so many degrees (the last rotation has to be saved). You can even set the rotation of actor a after the move to face the apparent direction it is moving. Things could get more complicated if actor b were allowed to get close to an edge of the world, but that can be dealt with.
nooby123 nooby123

2012/4/5

#
Thank you very much!
You need to login to post a reply.