I am making a game and I need an arrow to point to the player when he is offscreen. However, rounding atan2 does not work and gets me stuck in an endless loop. Here is my current code:ActorHelp is a custom class with common methods, and tip is just an object.
public void ensurePos() { if(ActorHelp.actorInvalid(tip) || ActorHelp.actorInvalid(this))return; tip.setRotation(getRotation()); tip.setRotation(getRotation(), getX(), getY()); while(!ActorHelp.actorInBounds(getWorld(), tip)) { tip.move(-1); move(-1); } double atan = Math.atan2(tip.getY()-getY(), tip.getX()-getX()); while(atan != tipDist) { atan = Math.atan2(tip.getY()-getY(), tip.getX()-getX()); tip.move(((int)atan) > tipDist ? -1 : 1); } }