Hello, I need help with figuring out a damage calculation that includes defense vs attack, i cant seem to figure anything out, also i such at math so that doesnt help at all.
Could you provide more information on what do you want to achieve
for example:
the offensive player has say 1000 attack value and the defensive player has 500 defense value.
each player has 100 health
the offensive player hit them with an attack that does 25 base damage, I want it to take into consideration the values of their attack and defense stats and add/subtract damage to the attack’s base damage depending on some equation used to solve for how much damage the attack does. but i don’t want it too be too weak or too op.
the equation part is what I can’t figure out.
lets say -
---- offensive part
local script
local dealDamage = script.DealDamage
local damage = 50
OnHit:Connect(function(hit, humanoid)
dealDamage:FireServer(hit, damage)
end)
server script
(Lets say the hitted player has 2 Defense value)
dealDamage.OnServerEvent:Connect(function(hit, damage)
local playerHitted = game.Players:GetPlayerFromCharacter(hit.Parent)
local defenseValue = playerHitted.Stats.DefenseAmount.Value
local damageToDeal = damage / defenseValue
hit.Parent.Humanoid:TakeDamage(damageToDeal)
-- basically we dealt here 25 dmg instead of 50 cus hitted player has a defense value of 2
end)
im giving you example via the raycast hitbox module so yeah
This is the easiest and laziest way you can implement it
You don’t necessarily need to be good at mathematics to be able to form a good damage calculation though you should know at least some basics. At the very least you should know how to use a calculator and how to plug in variables to test what you come up with. You can even use some references online to help you out in creating a damage formula.
There’s no concrete formula or mathematics that you need to follow to create yourself a damage formula – it can be as complicated or as simple as you’d like it to be. Just make sure that when you’re writing up your formula you do lots of testing with different values. Something that helps you develop your calculations and offset some values is having constants.
My personal recommendation is working with low base values. Ultimately most of the best damage formulas will deal in percentages. Percentages are nice, easy to work with and understood by a lot of people when you want to display them to the user. You should also work with a diverse amount of numbers so you have more variation. It’s difficult to form one that scales well off of a few inputs.
You can start by figuring out the fundamental parts of your damage formula which are how to plug in your base stats. All damage formulas at the end of the day are simply ATK * DEF
where ATK > DEF
and both ATK and DEF are greater than or equal to 1.
A common way to derive a base defense factor is to have your defense added to a number that would otherwise divide by itself. This defense factor, assuming you don’t want to do anything further with it, becomes the number you multiply incoming attack by.
defenseFactor = ATK/(ATK + DEF)
You can then check out different numbers to see its effectiveness. Let’s suppose that the incoming damage, whatever the calculations end up being, comes out at 50. Change DEF at your own leisure and then multiply 50 by it to see the results.
DEF = 50, ATK = 50/(50 + 50) = 25
DEF = 1000, ATK = 2.3
Obviously incredibly rudimentary and you can play around with different inputs given from the attacker or the target but hopefully that provides some direction and advice. Raw attack itself often ends up being just a lot of added numbers and multiplication as does defense. Difficulty will probably come from finding good numbers to harmonise both calculations.
i see, this helps me understand a lot better on how to go about this, thank you