Rotation of turret

Hi there.
We use the function Math.atan2(y,x) to find the angle between the turret and the player.


onCilpEvent (load) {
  var speed = 2
}
onClipEvent (enterFrame) {
  dx = this._x - _root.player._x
  dy = this._y - _root.player._y
  radians = Math.atan2(dy,dx)
  degrees = Math.round(radians*180/Math.PI)
  if (this._rotation < degrees - 90) {
    this._rotation += speed
  }
  if (this._rotation > degrees - 90) {
    this._rotation -= speed
  }
}

So the turret would then turn to the player at a speed of 2 all the time.

But then I observe a problem. See the attached picture.

The turret works normally when the player is in the regions around the three crosses. However, it would rotate continuously in the region around the red cross. Why is there such a problem?

//edit: If you don’t know what on earth am I talking about through words, please have a look at the example that I’ve attached. I published it for Flash Player 6 or above so that everybody could view it. Thank you.
//edit: And I could observe that the picture is not clear at all… Please use the example instead then.