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

2018/12/17

How to turn towards actor?

343qwm29 343qwm29

2018/12/17

#
I've been trying and deleting lots of code trying to make an actor that turns towards another actor when it is created. I don't have any code to post because I decided to start from scratch. Can somebody please help? (the actor I want to turn towards is called DancingQueen, the actor I want to turn is called Beam)
danpost danpost

2018/12/17

#
343qwm29 wrote...
I've been trying and deleting lots of code trying to make an actor that turns towards another actor when it is created. I don't have any code to post because I decided to start from scratch. Can somebody please help? (the actor I want to turn towards is called DancingQueen, the actor I want to turn is called Beam)
For the beam to know where to turn towards, it will need the location coordinates of the DancingQueen object in the world. That entails getting a reference to the DancingQueen object (to begin with). This can by done with:
Actor dq = (Actor)getWorld().getObjects(DancingQueen.class).get(0);
(best with only one DancingQueen object in the world). Then, the turning is simple:
turnTowards(dq.getX(), dq.getY());
343qwm29 343qwm29

2018/12/17

#
Thank you for your help, and there is only one dancing queen so this works.
You need to login to post a reply.