How to Make Lines Connected Point-to-Point from A to B?

seto007
Wed, 11 Aug 2021 06:20:13 +0000
UI

Hello. I have been making a map navigation system meant to be similar to the one in FTL for the past 2 days. For reference, the FTL map navigation system can be seen here:

To do so, I have compiled a blueprint which places a single button (named “stars” here) in every single a quadrant of a 8 by 4 grid that makes up the map screen (with a few pixels of padding so that they don’t spawn too close to each other), with a random selection of up to 15 (usually 3-8) of these stars being made invisible after placement. From there, a random star of the 5 furthest to the left, and of the 7 furthest to the right, are made into the “start point” (seen in red) and “end point” respectively.

From there, I run the OnPaint function once with the below graph:

In case it’s tricky to follow, what this function does is get distance between the a visible star (first for each loop element) and gets it’s distance to every other star that is visible (second for each loop elements). From there, it compares the distance of the first start to every other star, and if the distance is either the shortest distance in the entire array of visible stars, or the star is within 275 pixels, it draws a line to that star to the HUD (with +20 pixels added to x and y because of the default slot position of the buttons being -20x and y with center anchors).

This produces a perfectly workable map in most instances where a player could find a path from start to end, as seen below:

However, the map generation sometimes doesn’t work as intended, with different sections of the map not being connected as can been seen below:

I’m not much experienced in programing or pathfinding, so while I wouldn’t be surprised if there’s a relatively simple solution like an algorithm that finds the shortest path between the start point and end point by comparing the points in every sector that isn’t on the left column of the grid and links them, I have no idea how I would go about setting such a thing up with the setup I’ve created.

Here are the blueprint pastebins for the [Event Graph][5], [Starting Point Creation Graph][6], [End Point Creation Graph][7], and [OnPaint Function][8] respectively in case you wanted to get a better idea of how I’ve gone about making this setup so far. Obviously it’s nowhere close to done, but that’s to be expected.

Thank you all in advance for any help provided, and for having such a helpful community!

9 posts - 5 participants