Jump to content
  • Advertisement
Sign in to follow this  
Crayz92

Help solving for x in exponential formula

This topic is 476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Edited by missionctrl

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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. Edited by Nypyren

Share this post


Link to post
Share on other sites

 

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!

Edited by Crayz92

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!