Changing the 3rd line of update to:
1
| this.rotation = (float) Math.toDegrees(Math.atan2(dy, dx)) + 89.65f; |
should fix the problem.
I would recomend adding a member variable like:
1
| final static float ROTATION_OFFSET = Math.toRadians(89.65f); |
and change the 3rd line of the update function to:
1
| this.rotation = (float) (Math.atan2(dy, dx) + ROTATION_OFFSET); |
Always keeping the rotation variable in radians will help a lot with avoiding errors like this. If you ever want the rotation in degrees, to show the player or something, just convert it on the fly.
The problem isn't the rotation (Although I did change my method to fit yours a bit more). It faces the player just fine.
The problem is when the player is moving, the enemy will stop moving towards the enemy, and instead do these weird little circles, causing him to be nearly stationary.
What zoto said, and also make sure that the angle you're applying cos and sin to is in radians.
I noticed when you quoted me, you had commented out the rotation offset.
The reason I've got that is because my sprite wouldn't face the right direction (he'd face 90 degrees counterclockwise of the direction he's supposed to face.
Edit: I fixed it, I figured out what my problem was. Thanks to the two of your for your help. Much appreciated.