How to have Damage scale up high at low level and then low at later levels

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Newby

i heard that you can use nth-root or logarithmic functions to do this but i dont really know these fuctions nor put in into script is there a more simpler way to tackle this.

:bust_in_silhouette: Reply From: AG

If I’m understanding your question correctly, you’d like higher level enemies to deal more damage, but as their level increases, the increase in the amount of damage from the previous level ought to lessen.

Logarithmic functions, and functions like the square root or cubed root describe this relationship, and are already implemented in Godot. For our purposes, logarithms and nth root functions provide very similar behavior, so I’ll just go over logarithms.

You may currently have something like this, relating level to damage linearly:

var level = 10
var damage = level

To relate damage logarithmically to level, you could instead write:

var level = 10
var damage = log( level)

However, you will likely notice some undesirable behavior around 0 and 1.
Namely, log(0) is undefined, and log(x) evaluated for any x less than 1 will be negative.
To rectify this, you could instead write:

var level = 10
var damage = log( level + 1 )

While this does scale in the way you described, the numbers might not be exactly what you’d like. Thankfully, you can tinker with this by adding in some coefficients, or changing in the base of the logarithm.

var A = 1 # Makes the curve steeper or shallower.
var B = 1 # Makes the curve more or less bent.
var C =  1 # Makes the curve up or down.

var level = 10
var damage = (log( level + 1 ) / log( B ) ) * A) + C 

I set A, B, and C all to 1, but you’ll have to decide for yourself what values of A, B, and C work out best for your game. When doing this, It might be helpful to visualize these functions on a graphing calculator. ( Desmos | Graphing Calculator )