x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.21
Tags:
more ▼

asked Nov 15 '18 at 07:22 PM in Blueprint Scripting

avatar image

Carnage97
5 1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Nov 15 '18 at 07:33 PM

avatar image

mightyenigma
3.7k 18 23 20

avatar image Carnage97 Nov 17 '18 at 12:16 AM

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

avatar image mightyenigma Nov 18 '18 at 03:48 AM

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.

avatar image ThompsonN13 Nov 18 '18 at 04:20 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

alt text

capture.png (343.8 kB)
more ▼

answered Nov 17 '18 at 06:43 PM

avatar image

ThompsonN13
10.1k 33 10 25

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question