If you have not read the previous topic I posted on this you may want to check it out, but that shouldnt be required. Anyway for my Tower Defense Game I can rotate a tower using this code:
double angle = Math.atan2(targetY - pixY, targetX - pixX) * 180 / Math.PI;
g2d.translate(x + Screen.room.blockSize / 2, y + Screen.room.blockSize / 2);
g2d.rotate(Math.toRadians(angle - 270));
g2d.drawImage(Screen.tileset_air[airID], -Screen.room.blockSize / 2, -Screen.room.blockSize / 2, Screen.room.blockSize, Screen.room.blockSize, null);
g2d.dispose();
but something strange happens. It will rotate just fine at certain angles for example if the mob is coming from the left, but if it is coming from the top or right, the tower wont stay on target and will just slightly go up and then down and so on. Can anyone see any faults in this code?
Thanks, cMp