BobGaming2000 encountered an issue a while ago when he was playing a game because the developer sucked at math. However, the dev learned how to fix the issue! But there’s another problem now. While BobGaming2000 was continuing to play the game, he leveled up and chose to upgrade his attack power by 1. He now has an attack statistic of 2.
BobGaming2000’s maximum damage should be 999 once he reaches the maximum attack statistic. However, BobGaming2000 noticed that his attack power didn’t increase that much despite this fact. This is because the developer still sucked at math and tried to use an equation that was now invalid.
Code
local SwordDamage = 53
local AtkStat = 2
local MaxAtkStat = 999
SwordDamage += SwordDamage * (AtkStat / MaxAtkStat)
I don’t think so. I don’t want the attack power to be random, I want it to increase by a statistic. You know how in some games you have statistics? For example, an attack stat, defense stat, etc. In those games, once you’ve maxed out a stat, in this case, your attack stat, you can only deal a certain amount of damage, such as 999, for example. This is what I want.
I assume you want the max level damage to be 999 with lets say 10 levels . Assuming you want to increase the damage by a fix interval , you would need to use this formula
local SwordDamage = 53
local AtkStat = 2
local MaxAtkStat = 999
SwordDamage += SwordDamage * (AtkStat / MaxAtkStat)
But we actually would need to keep track of it’s default damage (53 in this case) to calculate it with any given AttackStat while also keeping track of how much Max damage you would want for the sword.
local DefaultSwordDamage = 53
local AtkStat = 2
local MaxAtkStat = 999
local MaxDamage = 999
To linearly scale our damage up to 999 you would find out how much damage we should be adding up on the default damage which can be found by: MaxDamage - DefaultSwordDamage = 946 or 999 - 53 = 946 in this case.
We’re doing this because we wouldn’t want the damage to be 0 if the AtkStat is given as 0, so instead we will add the DefaultSwordDamage later to ensure the player never has to do 0 damage.
So then you would calculate (MaxDamage - DefaultSwordDamage) * (AtkStat / MaxAtkStat) since (AtkStat / MaxAtkStat) gives us a number between 0-1 so this multiplication would be our scaling factor.
This equation would give us a number between 0-946 so obviously we have to add the DefaultSwordDamage (53) after we get our results to make our calculation 53-999.
Heres the full code:
local DefaultSwordDamage = 53
local AtkStat = 0 --> We will use the sword's default damage if this value is 0.
local MaxAtkStat = 999
local MaxDamage = 999
local SwordDamage = DefaultSwordDamage + (MaxDamage - DefaultSwordDamage) * (AtkStat / MaxAtkStat)
Your best call on making the players “notice the damage change” is to decrease the MaxAtkStat to a lower value or increase MaxDamage to a higher value.
Additionally you could use an exponential interpolation function for the damage to increase faster but slow down when reaching the end.
Very confusing, but super helpful! Thank you for the detailed explanation and code sample! I will be sure to bookmark this! I’m so glad that there are some math whizzes around here. Math is my fav subject, but man, I suck at it more than I thought! Thanks again!
@skyblox7862 Not quite but thank you for trying to help! All help is always appreciated!