Creating a Motion Tracker Eque minimap

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

I’m looking to create a radar minimap sort of thing that acts like a motion tracker from Aliens while also showing you your objective, it’s a top down 2d shooter game, I’ve looked up tutorials but so far they’ve either been sort of like little tricks (Like making a copy of a map and showing it very small in the corner of your screen but that’s not only too much effort as you’d have to either do some extra work recoding new ones every time, implement export vars, or some other third possible way to make it easy on yourself.) I just want a nice way of having one node I can drop in the canvas layer of any of my scenes that acts like a motion tracker and shows where your objective is relative to you, any help at all is appreciated.

:bust_in_silhouette: Reply From: cm

There are two low effort versions of this that come to mind.

The lowest effort is adding a second viewport to your screen with a camera that’s very high overhead. You’d have to figure out how to make your objective stand out, or how to hide anything that you didn’t want to show in the map.

The second is more like an actual radar with no map, and with dots indicating the objective’s proximity to the player. You can do this by finding the position of each objective relative to the player, scaling that down to fit your radar, and drawing all of that to your screen. The drawing can be done with sprites, texture_rects, or manually.

Here’s some quick pseudo-code to help convey the idea:

var radar_center = Vector2(50, 50)  # position of the radar on screen
var radar_radius = 40
var radar_range = 500  # maximum distance the radar can "see"

for each objective:
    # get the position of the objective relative to the player
    # you might want to use global positions here
    var p = objective.position - player.position

    # check if objective is out of range
    var real_distance_to_player = p.length()
    if real_distance_to_player > radar_range:
        # if this objective is to too far away, skip it
        continue

    # scale the relative position to proportionally fit on the radar
    var position_on_radar = ((p / radar_range) * radar_radius)
    # move the position relative to the radar's center
    position_on_radar += radar_center

    draw_dot(position_on_radar)

Thanks for your help

IVTheSimple | 2022-05-18 18:33