Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How do I clamp a float?

A topic by Pedderbab created Dec 30, 2020 Views: 2,520 Replies: 4
Viewing posts 1 to 3

I'm using UE4 and i can't figure out how to make the health and stamina only be between 0-100, how can I do that?

Host (1 edit)

I think that this should help,  despite me not being that familiar with unreal, https://answers.unrealengine.com/questions/296900/how-to-clamp-a-float.html

Not sure how to do it with Unreal Engine's stuff specifically, but the logic is pretty simple. Just create a function that takes in the value, a minimum value, a maximum value, and use if statements to return the proper value. Here's the gist in C++ that you should be able to copy and paste and use directly in UE4:

double Clamp(double value, double min, double max) {
    if (value < min) value = min;
    if (value > max) value = max;
    return value;
}

unfortunately i'm using blueprints, but thanks for trying

Host

Maybe this documentation could help, https://docs.unrealengine.com/en-US/BlueprintAPI/Math/Float/Clamp_float/index.ht...