Answer the question
In order to leave comments, you need to log in
How to make a gradual increase in damage for the absence of N-ovo health?
I'm not very good at math, so I don't really understand how to implement the solution.
I need to do this:
The less health the player has, the more damage he will do.
In this case, maxMulty must be involved.
Whatever it is, it would not be a banal check through if
if hp < 24 then
damage * 4
end
local maxMulty = 4
local damage = 100
local hp = 24
local maxHP = 100
local percHP = hp / maxHP --Получение процента от хп
Answer the question
In order to leave comments, you need to log in
Let's add an extra values for convenience of presentation:
local startDamage = damage -- Начальное значение на отрезке
local endDamage = damage * maxMulty --Конечное значение
percHP==1
percHP==0
percHP==0.5
(startDamage + endDamage)/2
startDamage/2 + endDamage/2
local function lerp(start_val, end_val, perc)
return start_val * perc + end_val * (1 - perc)
end
lerp(damage, damage * maxMulty, percHP)
function lerp(start_val, end_val, perc)
return start_val * perc + end_val * (1 - perc)
end
print(lerp(100,400,0.9)) -- 130
max_health = 100
current_health = 24
max_damage_multiplier = 4
get the current health percentage (current_health / max_health)
flip it to get the increase from lesser health (1 - current_health / max_health)
multiply the maximum possible multiplier by the resulting percentage, and get:
current_damage_multiplier = max_damage_multiplier * ( 1 - current_health / max_health )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question