Making a 2d "radar" for space game

Hello all -

I am making a space turret defense game, and my main ship is going to be the center of the action. However, I want to make a 2d overlay minimap / radar type thing so that players can see where the enemies are in relation to the main ship. The idea would be that the radar is a circle with lines denoting distances, such as the main ship in the middle as an Arrow or something, then a circle around that meaning 500 meters, another for 1000 meters, etc. I have enemies spawning all over around the ship, and above it. How would I translate their positions around the ship on the grand scheme of things to a small dot that moves on the "radar" ?

I would need some kind of conversion of distance that dis-regards up/down movement (so radar is 2d) but still keeps the relative distance away from the main ship so its actually reliable. I would hope to make something that can have different color dots on the radar for different enemy types, with size being relative to the enemies size.

How would I begin to code something like that? I'm not asking for anyone to write it for me, but a few points on how I could make a system like that work would be great.

Thanks! Marcin

I'm only starting out with Unity, but what you're describing is essentially the rendering problem, only targeted to a map instead of the entire screen. So you could approach it that way and build a transformation matrix composed of translation, scale and projection matrices (see the OpenGL redbook), and a separate Camera to render your 2D objects. Unity even has render to texture capability which would completely solve your problem, but it is a Pro feature. You can easily set this up though without using render to texture.

I'm not sure how you want the radar to function (e.g. fixed orientation, relative to the player, etc.), but in each case, transforming the positions of interest to 'radar space' will be similar.

If, for example, the radar has a fixed orientation and is aligned with a cardinal plane, you would simply project the positions onto that plane by zeroing the appropriate component. If on the other hand the radar is always relative to the ship, you'll use Transform.InverseTransformPoint() to transform the positions to local space, and then again zero out one of the elements to project them onto the ground plane.

At this point you have the 'radar position' for each object, but not necessarily scaled appropriately. Scaling however will be a simple linear mapping based on how many 'radar units' equals one world unit.

For rendering, there are several approaches; searching Unity Answers and/or the forums for 'minimap' should turn up some relevant discussions on the topic.