2D How to make an object orbit around the player according to the position of a target.

Hello!

I am trying to make some kind of threat indicator. It will point towards an enemy and track the enemy in an orbital fashion. The image below will definitely explain it better. The black circle is the player and the red triangle is the indicator. The red triangle can only move on the green circle and always points towards the red circle. I have succesfully done the pointing towards the red circle part but how do I move the pointer in the orbit accordingly? How would you go about coding this?

If you have the arrow origin/pivot point in the center of the players transform then you simply calc the vector towards the enemy and then rotate the arrow to that angle.

public Transform Player, Arrow, Enemy;

private void Update()
{
    //Calc Vector from player to enemy
    var direction = Enemy.position - Player.position;
    //Calc rotation from the player to enemy. 
    var rot = Quaternion.LookRotation( Vector3.forward, direction);
    //Apply rotation
    Arrow.rotation = rot;
}
3 Likes

Thanks alot!