How could I implemented a top-of-screen heading compass for a 3D game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SneakySteve

I’d like to implement a compass at the top of the screen for my first-person character. Something like what can be seen in this image at the top of the screen. I thought about making a texture that held all the bearings, and then sliding it left or right somehow, but I’m not sure how I would get it to disappear when going outside the background of the compass, without implementing another background that would cover the game view. Has anyone tried something like this? I can’t find anything online for it, though I could just be searching wrong.

:bust_in_silhouette: Reply From: haydenv

Position and size a Control node near the top of the screen.

In the inspector dock, under Rect, check the checkbox that says “Clip Content”.

Now the Control node’s children will be partially invisible if they are partially outside the Control node’s bounding rectangle.

There will be a problem if the player turns more than 360 degrees. I hope someone can provide a clever way to deal with this issue. I thought about it and my line of thinking goes something like this:

Make three TextureRects, each with the compass texture, and each as children of the Control node. Position them side by side so they seem like one long compass texture that repeats. Everytime the player rotates to the left or right, move all three TextureRects to the left or right. If the player rotates far enough to the left then the middle TextureRect won’t be in view anymore, only the leftmost TextureRect will be. If that happens, then reposition the rightmost TextureRect to be on the far left. And vice-versa if the player rotates far enough to the right.

Please leave a comment indicating what, if anything, requires further clarification.