- Home /
Show object location with arrow
Hi all, I am making a 3d game, and I want to have a arrow over the player or on my canvas that will point to the location that the player is supposed to go, ex. to an npc. How would I do this?
Answer by RodrigoAbreu · Feb 07, 2021 at 03:44 AM
@unity_23aferg8 Basically what you need to do is:
Calculate the direction from your player position to the target object in the world;
Then you need to check the angle between those two entities: (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg) % 360 would do the trick;
Then you need to set the UI element (the pointer) eulerAngles (from its transform);
And then make sure to convert the position of the player from WorldToScreen position and se the pointer UI element position to always be on the player or maybe with an offset displacing the element slightly away from the player object.
Or instead of keeping the UI element on the player, you could also force it to be in the target's position, but clamping its position to never go out side the screen.
CodeMonkey has a video explaining how he approached that. https://www.youtube.com/watch?v=dHzeHh-3bp4
No problem @unity_23aferg8, I did something similar a couple of weeks ago.
Your answer
![](https://koobas.hobune.stream/wayback/20220613024721im_/https://answers.unity.com/themes/thub/images/avi.jpg)