How to make a progress bar increase as it gets closer to an object?

In my current game, I only want to allow my character to travel so far so I made an invisible wall spawn a certain distance from the player but I want the player to be able to tell when he’s reaching that point with a progress bar. How can i make the progress bar increase as it gets closer to the object?

Progress bars can be bound to a function or variable that returns a percentage, a float between 0.0 (for 0%) and 1.0 (for 100%).

So you can find the nearest location on the wall (how you do that will be the trick to figure out), use the Distance node on that and the Player Pawn’s current Location, clamp that number to a value between 0 and 100,000, and then divide THAT number by 100,000 and you’ll have your percent float between 0.0 and 1,0 which will shrink the progress bar down until you hit the wall.

Instead of 100,000 you can use a variable default value of whatever you want the maximum distance the bar cares about to be, beyond which it will just cap out at 100%

So to figure out where the nearest point on the wall is, I’m not sure but there are lots of ways to figure it out and maybe even a blueprint node that lets you do it and for instance if you have 4 such walls boxing in the large area, you could run it 4 times and just keep the smallest value for the distance.

Can you show me via example im trying to do what you are mentioning im just confused i apologize

the trouble is that you would need to find the closest point of the boundary then calculate the distance to that point on a very regular basis which could cause a performance loss. depending on your situation you may want to look into just using something like a collision volume to tell the player they are going out of bounds, a hollow blocking volume, or just calculate the distance from the center of the level. the last option mentioned is very easy, you just get max distance from center and player location then normalize to range which will return a 0-1 value.

if you choose to pursue your current method though below is a example of the logic needed. basically you need to have an array of points which represent the boundary of the level, then you need to find if there was a line between each point where on the line am i closest to. thats basically the entire top half of the script, for line from point 0-1 how far is the player from the line, is that closer than the current closest line value, if yes set this line to the closest, repeat for line points 1-2, etc.

now this would all work well for a circle where all points are equal from the center, but in the case of square or irregular shape we need to provide a max range value so we have something to normalize to since a progress bar requires a 0-1 value.

Sorry I tend to answer questions when I am away from my computer so I cant get to the unreal engine and create the solution the take a screenshot for you. Looks like @ThompsonN13 has a good screenshot and alternative solution for you.

is a solution but not a very performant one in my opinion haha