I'm just trying to get started at this, so please bare with me.
I have an enemy sprite that sits at a specific x,y coordinate. I want that sprite to be able to rotate to follow my player as it moves around it.
The problem I am having, is that atan2 seems to only work in 180 degrees at a time. So, what happens, is when my player breaks even on the Y coordinate, the enemy stops following.
Here's my code so far:
Then, I SetRotation(Angle). Any ideas?
Thanks!
I have an enemy sprite that sits at a specific x,y coordinate. I want that sprite to be able to rotate to follow my player as it moves around it.
The problem I am having, is that atan2 seems to only work in 180 degrees at a time. So, what happens, is when my player breaks even on the Y coordinate, the enemy stops following.
Here's my code so far:
Method TrackPlayer() Local DestAngle:Float = ATan2(PlayerY-Y,PlayerX-X) If DestAngle > Angle Angle :+ 1 ElseIf DestAngle < Angle Angle :- 1 EndIf EndMethod
Then, I SetRotation(Angle). Any ideas?
Thanks!