Hi
How can i rotate an object to face another object, it is to be placed as the outcome of an if statement.
So if object b is.... turn object b to face object a?
Thanks for your help!


1 2 3 4 5 6 | static int x, y; public void act() { x = getX(); y = getY(); } |
1 2 3 4 5 6 7 8 9 10 11 12 | // put the coordinates of the object you want to turn to public int point_to( int x, int y) { int dx = x - getX(); int dy = y - getY(); double rotation = Math.atan2(dy, dx); rotation = Math.toDegrees(rotation); return ( int )rotation; } public void act() { setRotation(point_to(ActorA.x, ActorA.y)); } |
1 | turnTowards(ActorA.getX(), ActorA.getY()); |
1 | ActorB.turnTowards(ActorA.getX(), ActorA.getY()); |
1 | static int x, y; |
1 2 3 4 5 6 | public void act(){ if (BinBump()) { turnTowards(lorry.getX(), lorry.getY()); } } |