So im trying to make an arrow point towards a position in my scene, i want to rotate the arrow to that position. I have tried to make the world position into a screen position and then subtracting the position of the arrow from that and then settig the rotation, but im having some trouble converting the rotation to make it right (or maybe i did something wrong another place). The script is attatched to the object i want it to point towards, here is my current code:
Vector3 viewportPos = Camera.main.WorldToViewportPoint(transform.position);
Vector2 worldObjScreenPos = new Vector2(
(viewportPos.x * canvasRectTrans.sizeDelta.x) - (canvasRectTrans.sizeDelta.x * 0.5f),
(viewportPos.y * canvasRectTrans.sizeDelta.y) - (canvasRectTrans.sizeDelta.y * 0.5f));
Vector3 rot = worldObjScreenPos - arrowRectTrans.anchoredPosition;
arrowRectTrans.rotation = Quaternion.Euler(rot);
But this gives me some weird results where the arrow starts spinning like crazy.