Exponential XP (Beginner)

I’m relatively new to any sort of coding; C# especially.

I’m still learning and I know this might seem pretty trivial but I’m trying to figure out how to go about making a xp/leveling system that goes off of xp that isn’t of a liner fashion. IE. Not, 50, 100, 150, etc.

Obviously, you could math it out and set the xp req per level. But is there a way I can do it with just a couple lines of code? And would you have to change anything as far as the typical “leveling” scripts go?

If you had something like:

if(currentXP >= nextLvlXP(currentLVL))

Or would you have to make some changes to it?

Also, I was looking for some examples or reference but, I’m not sure if this is what I’m looking for.


And I’m sorry if the code sample didn’t work, I clicked on it and used it however it doesn’t look like the code that’s shown like in everyone’s posts here (Although maybe it just doesn’t show up in preview?).

Thanks for the time! :slight_smile: Hopefully I explained myself well enough (I’m tired!) And, does anyone else have a ridiculously hard time with tags?

EDIT: Broken link was broken.

As you can easily find on the net, most games ( which involves XP )seem to be based on a quadratic function and not exponential. The exponential function has the “little” problem that it grows way too much when you go higher. You could compensate it a bit by increasing the XP gain with each level also in a exp-fashion.

If you have a XP ↔ level relation ship based on the quadratic function like this:

    level = Mathf.FloorToInt(constant * Mathf.Sqrt(XP));

You can calculate the required XP for a certain level like this:

    XP = (level*level) / (constant*constant);