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

2013/6/19

How do track rotation from actor to mouse

gman9627 gman9627

2013/6/19

#
I wanted to have a shoot actor go in the direction of the mouse but I could not get the direction the mouse was in from actor need help
Gevater_Tod4711 Gevater_Tod4711

2013/6/19

#
Therefore you can use the method turnTowards. Use the location of the mouse as the parameters and your shot actor will turn in the direction of the mouse:
1
2
3
4
5
6
7
public ShotActor() {
    //you should do this in the constructor. Otherwhise the bullet will follow the mouse all the time;
    MouseInfo mouse = Greenfoot.getMouseInfo();
    if (mouse != null) {
        turnTowards(mouse.getX(), mouse.getY());
    }
}
You need to login to post a reply.