I'm trying to make it so defense cuts damage in half every time defense doubles, starting with 200 defense giving 50% damage resistance. My problem is I'm having trouble finding a formula that works well. Usually anything with division causes a headache as damage/(def/100) means that I can't have defense be zero or a low number (it would increase how much damage a player takes). Mathematically alone, I've also been trying things with exponents and even logarithms, but to no avail. I can almost guarantee there is a mathematical formula that will work, but I lack the PhD and experience to figure it out. Any ideas? The numbers might look like this:
Defense 0, 200, 400, 800
Damage Taken 1000, 500, 250, 125
1000 * (0.5)^(b.def/200) should do it. Though which engine? This really should be in engine support as exact details of how to enter it depends on the engine used.
Then there isn't a simple way to make what you want work. If doubling the defence halves the damage, then halving the defence will double the damage, and that means very low defence will produce very high damage.
The only thing you could do (unless you decide to change tack and go with bgilisp's formula) is to use an if-then: if defence < 200, use [formula A], if defence > 200 use 100000/b.def.
(I haven't specified what "formula A" would be since the only data point you've given is (0, 1000), which on its own isn't enough to know what the output should be. What output values do you want for defence 50, 100, 150?)
See the issue is you set values that *cant* be done as a true exponential by the normal exponential equation. A true exponential would change powers every 200 defense. Not every double of defense. A change to allow 800 to be treated as a power of 3 would also shift the other numbers to no longer match.
Exponential equations use two points to connect. I used the first two. If I use the last two it will be a different equation but not hit the others. You will need to pick one as you got 4 points that do not go together for an exponential equation of the form y = C*a^(x/D). C is the value when x = 0 so that was easy. A is y2/y1 (500/1000 here), D is how far the next point is (200 apart).
This is covered in most precalculus books if curious.
Turans method above appears to work for up to 800, but if you are allowing 1600 def then 1600/200/2 = 4 + 1 = 5, so will be power of 5 not 4, and the current pattern has 1600 is power of 4. So I'd honestly suggest changing it a little instead.
Also engine this is in is required, as this has to be moved to engine support as this part you posted in is for if you should do something not how to do something. If not posted I'll take an educated guess.
Another angle to consider, "Double the defense to halve the damage" gets messy if you think of the situation where you move a defense stat from 0 to 1. Proportionally that an increase of infinity percent which won't work as the OP stated clearly we want a formula that can handle defense values of zero
If curious, this is why I did this for my division formula:
(attack formula here)/(b.def + 20).
That +20 in the denominator makes sure it never goes to 0 there, as at worst, you will be divided by 20.
Thinking about it, I think I will do damage resistance equals def/4. This will allow me to have 100 def give 25% resistance at lv. 1, and will allow me to have 50% resistance with 200 defense (cap at 50% for armor). I'll also add in a level scaling feature so that more defense is needed per level to keep the same amount of resistance. This will allow me to balance offensive and defensive equipment easier mathwise. I can always have spells cut damage in half multiplicatively, as that will still allow me to stack less damage taken.