Need help condensing large values into a 0.0-1.0 format for a "power meter" progress bar

Hello All,

I have a golf project I working on and I’m having difficulty getting the shot meter to do what I want.

I have the Widget BP built. It displays on screen, and responds accordingly to player input. However, the value for ‘Launch Speed’ FAR exceeds 1.0. Therefore, the meter fills up instantly.

I have the ‘Launch Speed’ variable that begins increasing when the button is pressed. It has a max value set via a ‘Clamp’ node. My issue comes from trying to convert the large float to a 0.0-1.0 value for the progress bar.

I’ve tried ‘Normalize to Range’, ‘Map Range Clamped’, even basic math (Launch Speed/max value. Every time I either get:

  • A low value that doesn’t allow my ball to shoot, but still fills my meter.
  • A low value that doesn’t allow my ball to shoot, and the meter fills accordingly.
  • The value raise as it should to max, but doesn’t register on the meter

I’m sure I’m just being dumb. Any help would be appreciated. Thanks in advance.

mapRange

Use the “Map Range Clamped” node to remap values from one range to another.
In your case the out range will be 0 → 1 for the progress bar

In the in value set your expected min and max values and pass in your current value into the value node.

First off: Thank you for your reply. I appreciate you taking the time.

I did a little research before I posted and the ‘Map Range Clamped’ was exactly what I thought my solution would be. However, it doesn’t seem to allow the value to get up to 1.0( or the 3000 max value).

Am I missing something simple in my setup? I’ve added the shots below (if I missed something you need, just let me know). The same value keeps coming up (.008336), so I think that’s something I can try to start with.


Working setup’ with no Map Ranged node


Current setup using Map Ranged node


Meter response with clamp added

Please let me know if you see anything I overlooked. Thanks again.

*As I was writing this reply, I had the idea to remove the first 'Clamp Float" and just use the Map Range node to handle that. I had the exact same value appear. I just can’t seem to get my Launch speed to convert all the way to 1.0.

I just had a thought:

The ‘Launch Speed’ variable is DIRECTLY related to the velocity the ball has applied when “shot”. When it’s set to 0.0-1.0, that will directly affect the power of the shot.

Should I create a second variable, ‘Meter Power’ for example, and set THAT to match ‘Launch Speed’ THEN do the conversion? That way the variable being reference by the shot process isn’t affected?

Let me know. I may be overthinking it.

To get a value of 1 you would need to pass in to the value node of “Map Range Clamped” equal to the value “In range B” (that’s the max)

Try printing out the value you are passing in.
.008336 is a very low value. If you reverse the node calculations

  • passing in .008336 as the value
  • in range A as 0
  • in range B as 1
  • out range A as 0
  • out range B as 3000

you get the value of 25.008

So you are only passing in 25 of the range between 0 and 3000. A very low value.

Also watch out when passing direct outputs of functions (stuff like random range etc). It’s usually best to cache information either into local variables or actor variables otherwise you can get misleading information.

Thank you again.

So this opened a very curious can of worms.

The 25.000x value is printed on screen with NO player input. My guess is the Tick event that calculates the math is adding values ‘by itself’. but is ALSO somehow preventing the percentage value to reach 1.0

image

I am at a complete loss at this point. Thanks for the advice. Sorry I’m not adept enough to be able to take it.

Add in breakpoints with F9 to key nodes (ones that have arrows through them) and step through the code checking values. I’m sure you’ll be able to catch where things are going wonky :slight_smile:

Just be sure to set the debug actor in the bp editor to the one in your scene (by default it’s set to “No debug object selected”)

Once again, Thank you for your reply.

I chased this stick until I made it work. Essentially I took the same value the ball was going to be hit with, divided by the max and applied to ta new variable being reference by the widget. Works like a dream.

I do have one more thing that pertains to this, but if I need to open a sperate thread for it; please just yell at me.

I want the value (launch speed) to STAY where the value is when the key is released. Basically, hold the key to raise it, let go, and the value stops. Press the same key, the value goes up again OR press a different key, and the value lowers and stays after release. Any ideas?

And once again, if this requires a separate question, just let me know. Either way, I will mark this answered so you get your deserved acknowledgment. Thank you again for taking the time.

I would look into some tutorials about the new enhanced input system and triggers for input actions. In them you can define if the action is a on shot, if it’s a hold action etc. You will have different outgoing pins depending on the triggers and modifiers you define there.

Create the mapping context in the same menu where you create the input action (it will have a yellow icon)

Setting mapping context in player controller

To get the enhanced input local player subsystem type in “enhanced subsystem” and it should find the node

Create input action

Setup input action triggers (when it fires)

Setting the input action inside of the mapping context

Implementing the input action

The result (print screen goes in reverse)
5

This is SUPER helpful. Thank you for the in-depth explanation. It is very much appreciated.

@demonicheddgehog If the issue has been fixed then can you mark the question as resolved?

can do.

My apologies.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.