0 votes

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.

Godot version v3.4.2.stable.official
in Engine by (53 points)

1 Answer

0 votes
Best answer

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.

by (152 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.