# [Geometry, trigonometry, vectors] Pointing to an object around specified circle

This gray little thing (let’s call it “pointer”) must point to the right white doll, and move only around player (left guy).
Doll and player can walk, so their position changes.

So the player is axis for this “pointer”, and distance between them is radius, which can be set.

I tried to implement this, but all I have is a mess, where “pointer” moves in almost random position, and not around player.

``````public class LookingDirectionMark : MonoBehaviour
{
public GameObject lookAt;
public GameObject axis;

private void OnEnable()
{
StartCoroutine(Moving());
}

private IEnumerator Moving()
{
while (gameObject.activeSelf)
{
GameObject o = gameObject;

o.transform.localPosition = LookAtAroundCircle(axis.transform.localPosition, lookAt.transform.localPosition, 1f);

yield return GlobalConstants.WaitForEndOfFrame;
}
}
}

public static Vector3 LookAtAroundCircle(Vector3 axisPosition, Vector3 pointToLookAt, float radius)
{
// y is z here
Vector2 vectorA = new Vector3(pointToLookAt.x - axisPosition.x, pointToLookAt.z - axisPosition.z);
Vector2 vectorB = new Vector3(pointToLookAt.x - axisPosition.x, 0);

//float alpha = Vector2.Angle(vectorA, vectorB);
float alpha = -Mathf.Acos
(
(vectorA.x * vectorB.x + vectorA.y * vectorB.y)
/
(
Mathf.Sqrt
(
Mathf.Pow(vectorA.x, 2) + Mathf.Pow(vectorA.y, 2)
)
*
Mathf.Sqrt
(
Mathf.Pow(vectorB.x, 2) + Mathf.Pow(vectorB.y, 2)
)
)
);

float betta = 90f - alpha;

float resultX = (axisPosition.x + radius) * Mathf.Cos(betta);
float resultZ = (axisPosition.z + radius) * Mathf.Cos(alpha);

return new Vector3(resultX, axisPosition.y, resultZ);
}
``````

Solved by using Vector3.LookAt function and adding “pointer” as a children for object that is looking at doll.