Help solving for x in exponential formula

Started by
4 comments, last by Crayz92 6 years, 10 months ago

I'm working on an exponential formula for my experience progression. Check out the sheet and graph here:

https://docs.google.com/spreadsheets/d/1uCWxAgvNljqjGWCr7mRcQcnW_qA0iD8Tw_2clGj-2aA/edit#gid=0

exp = ROUNDDOWN(600 + (x ^ 4.75)), exp is amount of experience, x is any level between 1 and 100.

My characters store only how much experience they have, so I need a function that plugs exp into the formula and solves for x to convert experience points to a floored level

From what I've gathered Logarithm is useful here, but I'm struggling to figure it out as my math skills aren't that great.

Advertisement
exp = ROUNDDOWN(600 + (x ^ 4.75)), exp is amount of experience, x is any level between 1 and 100.

The easiest way to do this is to invert the exponent.

x = ROUNDDOWN( exp ^ ( 1 / 4.75 ) ) - 600

I don't see an exponential formula here (ie n^x, where n is a number). See also

https://en.wikipedia.org/wiki/Exponential_function

what you have is a power function x^n, see also

https://en.wikipedia.org/wiki/Power_function

Inverse of power function is to take to the 1/n power: y = x^n -> x = y^(1/n).

Also, I'm not one to judge your game design, but is there a good reason you are using such large numbers? I bring this up because you're generating numbers that are well beyond the maximum size for a standard integer variable, which is a little over 2 billion.

Another approach I've seen used in games: instead of having a single pair of functions, we just have a lookup table instead. I.e.:

Level 1 = 100xp
Level 2 = 300xp
Level 3 = 600xp
...
Level 100 = 1,000,000xp
So if you have some number of XP, you find the highest entry in the table where entry.xp <= player.xp.

The advantage is that you can change your level curve arbitrarily instead of trying to find the inverse of some (potentially very) complicated equation. For example, you could make levels 1-60 go quickly, then have a sudden slowdown from level 61 to 100.

The disadvantage is that if you only store XP in a variable and calculate level on the fly every time, it means doing a binary search every time you use it. If this becomes a problem I definitely suggest caching the Level value as well.

exp = ROUNDDOWN(600 + (x ^ 4.75)), exp is amount of experience, x is any level between 1 and 100.

The easiest way to do this is to invert the exponent.

x = ROUNDDOWN( exp ^ ( 1 / 4.75 ) ) - 600

Looks easy enough, thanks!

I don't see an exponential formula here (ie n^x, where n is a number). See also

https://en.wikipedia.org/wiki/Exponential_function

what you have is a power function x^n, see also

https://en.wikipedia.org/wiki/Power_function

Inverse of power function is to take to the 1/n power: y = x^n -> x = y^(1/n).

Thanks for the correction. I will find the time to read these articles, I'm really lacking in the math department :)

Also, I'm not one to judge your game design, but is there a good reason you are using such large numbers? I bring this up because you're generating numbers that are well beyond the maximum size for a standard integer variable, which is a little over 2 billion.

That's a good point. I'm following the design of other games who reach 3 billion+ experience for maximum level, so I suppose the long data type would be needed. I might just lower my numbers to fit in an int and make up for it elsewhere, but it's all really early stages still :)

Another approach I've seen used in games: instead of having a single pair of functions, we just have a lookup table instead. I.e.:


Level 1 = 100xp
Level 2 = 300xp
Level 3 = 600xp
...
Level 100 = 1,000,000xp
So if you have some number of XP, you find the highest entry in the table where entry.xp <= player.xp.

The advantage is that you can change your level curve arbitrarily instead of trying to find the inverse of some (potentially very) complicated equation. For example, you could make levels 1-60 go quickly, then have a sudden slowdown from level 61 to 100.

The disadvantage is that if you only store XP in a variable and calculate level on the fly every time, it means doing a binary search every time you use it. If this becomes a problem I definitely suggest caching the Level value as well.

I'll keep this in mind in case the formula based experience progression doesn't turn out!

This topic is closed to new replies.

Advertisement