Calculating mana percentage to lay down time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I have a mana system inside a combat game
The game is like soulshatters, when you get knocked back you lay down on the ground for a time calculated from your mana to full mana percentage. But im very bad at math so I dont know how

For example, the time you stay on ground at full mana is 1 second
It increases the lower your mana
I wanna make it precise so not something like if mana > 100 then stuff

somthing like this?

local Time = 1 * mama

That’s pointless, why woukd you multiply the mana by 1
Also if the mana is 100, that means the time is 100???

I want it to be percentage based

assuming I’m understanding this correctly, you’ll probably want to make a note of the maximum amount of time someone can be ‘downed’ for, which would be if their mana is empty / at 0.

once you have their current mana, the maximum and minimum their mana CAN be (100 and 0), and the ranges you want the downed time to be between (1-10), you can run a simple map function to calculate what the downed time will be based on the current mana.

for example:

local maxMana = 100
local minMana = 0
local currentMana = 50

local minDownTime = 1
local maxDownTime = 10

-- mapping function
function map(x, in_min, in_max, out_min, out_max)
    return ((x - in_min) / (in_max - in_min)) * (out_max - out_min) + out_min
end

-- map the current mana, which is between 100 and 0, to a range of 1 to 10
print(map(currentMana, 100, 0, 1, 10))
 -- prints 5, since the mana is at the halfway point of 0-100, and therefore the time to be downed is at the halfway point of the values set, 1- 10
1 Like