Download

Enemy detector bar

Hi guys sorry this one is probably easy for most of you but I can’t seem to figure it out.

What I am trying to do is create a bar HUD for the player that detects the enemy based on distance.

The closer the player gets to the enemy the more the bar fills up.

Now I have a custom event that finds out the distance between the player and the enemy which is fine .

And I have another variable called fill variable which is clamped all I want to do is as ( distance decreases - increase fill variable ) or as ( distance increases - reduce fill variable)

So as the player gets closer to the enemy the fill variable will increase which will fill up the bar on the widget.

Thanks for you’re time

You will need to convert the value over to be between 0-1 and then you can just drop a bar into the UMG and set its value based upon your variable by binding it’s value.

I appreciate you’re responce but please be more helpfull/specific.

What value do I need to convert??
What nodes do I need or how do I convert it??

Again what value am I setting in the umg . And I don’t see how just binding it will work.

I already have the fill variable binded to the bar. I can manually increase or decrease the bar by changing the fill variable value but my question aw how to make it work automatically based off the distance between the enemy an the player . I already have the distance I just need to know how to combine the two to work together.

Thanks

Can anyone help thanks??

assuming you have a progressbar its fill state is defined between 0-1 (where 0 is zero filled).

What you need is a value which you can map between 0-1. Which value that is in your case, you already found out: its the distance between your character and the enemy.

  • To get the distance, you will need the vector between your objects (Location A - Location B).

  • After that you can get the Length out of the Vector, now you have a scalar value which represents your distance

  • To Update your bar, provide a Function which has a float as Input, as you may already know, you need to call this function and give your VectorLength over to the
    Widget

  • inside the widget: you´d need to Map this distance between 0-1 (there is a Math Node for Mapping)

check this out :wink:

MapRange.png

  • the first input (Value) is the distance you calculated

  • InRange A/B are the minimum and maximum values for your range
    inside the picture you see that i set them to 0 and 100, which means i want to map between 0 and 100

  • OutRange A/B are the minimum and maximum output values and since your progressbar works between 0 and 1 these are the values to set here

lets say we have an input of 50 as distance, the mapping will result a Return Value of 0.5

maybe this helps
Wallhalla