1
\$\begingroup\$

I'm working on a RPG game, however, I am not the amazing person at math that I wish I was, although someone suggested a logarithmic equation would work well. My current idea is for this:

You start off getting levels relatively quickly (lower xp amounts), then once you get higher up like 20-30 maybe it starts to take longer and longer to level, ending somewhere around 10-15 million experience for level 100. Can anyone offer me an equation or suggestions on how to do this? Thanks :)

\$\endgroup\$
5
  • 3
    \$\begingroup\$ gamedev.stackexchange.com/questions/20934/… \$\endgroup\$ May 7, 2013 at 19:44
  • \$\begingroup\$ That will not work well for me, mostly because A. This is java, B. I'm trying to make it so it works with only the xp, and you don't need to save the levels. \$\endgroup\$ May 7, 2013 at 19:55
  • 2
    \$\begingroup\$ Java or C the math is the same. And you don't need to save the levels, that example just had the levels to show, it was still a formula to generate it. \$\endgroup\$
    – Rangoric
    May 7, 2013 at 20:03
  • 3
    \$\begingroup\$ A.) The link Roberts provided is not exactly language specific, don't ignore it the second you see a little bit of c++. B.) There were no levels being saved, that was just the output to help you visualize what was happening. (Read the Accepted Answer) \$\endgroup\$
    – Fizzik
    May 7, 2013 at 20:04
  • 1
    \$\begingroup\$ The answer should give you the basic formula you need. If you want to compute your current level based off the amount of xp you have then you would simply run the algorithm while keeping a sum of (new_xp - old_xp) until the next levels xp requirement is greater than the xp that you have. Translating the function should be pretty easy and take only a few minutes (I'd do it for you but this question is going to be closed as a duplicate soon enough). That being said you should consider keeping track of levels and xp for the next level to simplify your math. \$\endgroup\$ May 7, 2013 at 20:54

1 Answer 1

6
\$\begingroup\$

If you want a logarithmic levelling formula that would simply be:

Level = Math.max( Math.floor( constA * Math.log( XP + constC ) + constB ), 1 )

For ~10 million XP at level 100 you should choose something like constA = 8.7, constB = -40 and constC = 111.

If the level gap rises too fast for your taste increase constA, decrease constB if you want the inital level gap to be higher, and finally set constC ~= exp((1-constB)/constA), in order to properly start at level 1.

Note that the appropriateness of any levelling formula depend completely on how fast players can gain XP at any given level.

See also: Algorithm for dynamically calculating a level based on experience points?

\$\endgroup\$
3
  • \$\begingroup\$ Hey, how would I get the experience from a level using this? @eBusiness \$\endgroup\$ Aug 31, 2014 at 11:34
  • \$\begingroup\$ I've tried this btw: (int) (Math.pow(10, (Math.ceil(level) - constB) / constA) - constC) \$\endgroup\$ Aug 31, 2014 at 11:49
  • 1
    \$\begingroup\$ @ThePixelPony The experience of a given level will always be a range, as level should always be an integer there is no point in ceiling it, rather you can calculate the lower and upper XP bound by feeding the inverted formula level and level+1 respectively. Note that my answer use base e logarithm, the opposite of that is base e exponentiation, so you should do (Math.exp((level - constB) / constA) - constC). \$\endgroup\$ Aug 31, 2014 at 12:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .