My problem is I don't really understand the math I am using here.
I have a node that gets notified when an enemy can see the player. It instances the seen-indicator scene for each enemy that currently sees the player and updates it's position each frame. When the enemy is on-screen it is positioned above the enemy's head using unprojected position. When the enemy is not on-screen, it should snap to an ellipse at the angle towards the enemy.
I have a formula that gives the point on an ellipse given an angle. That part looks like it is working. What I am having trouble with is how to calculate the angle. Alternatively, I could use a formula that gives a point on an ellipse using something other than an angle.
As you can see in the gifs, from above it works, but horizontal points the wrong way and it stays on the side for most of the spin, moving across to the other side very quickly.
Any ideas?
(Can't get the gifs to work, here are imgur links)
func update_tag(tag: Control, target: Vector3):
var is_behind = camera.is_position_behind(target)
var unproject_position = camera.unproject_position(target)
if (not is_behind
and unproject_position.x > lower_margin.x and unproject_position.x < upper_margin.x
and unproject_position.y > lower_margin.y and unproject_position.y < upper_margin.y):
#is on-screen
# is on-screen code here
else:
#is off-screen
if is_behind:
unproject_position *= -1;
var x = unproject_position.x
var y = unproject_position.y
var angle = atan2(y - center.y, x - center.x)
tag.RectPosition = center + Vector2(ellipse_half_width * cos(angle), ellipse_half_height * sin(angle))
tag.RectRotation = 0
tag.RectScale = Vector2.ONE