Average time as slider value?

I need some math help. Hope this makes sense…
I’m trying to get the average lifetime of enemies (last + current / 2) then I need to display as a slider which ranges from 0 to 1. I’ve tried dividing the average float by the longest lifetime which does make it range from 0 to 1 but the problem is the max value needs to be the shortest lifetime.

Hi,

Hope you’re doing well.

I suggest you use the nodes MapRangeUnclamped or MapRangeClamped.

It will make your life easier, imagine you have:

float Health = 75.0f; //between 0.f and 100.f

// You can map it in order to get the result between 0.f and 1.f
float Slide = MapRangeClamped(Health, 0.0f, 100.0f, 0.0f, 1.0f); 

// Slide result will be = 0.75f

I think this nodes can solve your issue no matter how the min and max change along the gameplay, as long you update in in the MapRangeClamped.

Hope that helps - take care.

2 Likes

Thanks but I think I solved it, the calculation was right but it needed to be inverted using 1-x.