Godot Version
4.3
Question
I have some units which are basic scenes made up of a collection of nodes (as typical). A few sprites, some scripts… etc.
These units can appear on the screen in random locations and move. I want to have a system where I can highlight a unit to indicate that it’s selected so that I can then act on it. Using keys on a keyboard, the DPad, or an analogue stick, I want to be able to select nearby units. So if the current unit is selected and I hit up on the DPad, it should move the selection to the nearest unit that’s generally above this unit.
All units should be able to be navigated to this way. If I had 1 unit with 3 units above it in a horizontal line, I should be able to press up to select one of them, then left or right to select the other 2, then down from any of them to return to the first unit.
I know there are control nodes but they seem to need to be able to program in what the nearest neighbor is for each direction. I won’t know what it is and it’ll possibly change frame to frame at runtime.
The only solution I can think of is to use a ray when pressing a button to see if it intersects with something and move to it if it does. This seems like it should be a fairly common practice of selecting things spatially using a controller, but I can’t figure out what algorithm is generally used to do so.
Any suggestions would be appreciated.