# RPG Logarithmic leveling formula?

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 :)

• gamedev.stackexchange.com/questions/20934/… – Little Helper May 7 '13 at 19:44
• 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. – VoidWhisperer May 7 '13 at 19:55
• 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. – Rangoric May 7 '13 at 20:03
• 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) – Fizzik May 7 '13 at 20:04
• 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. – Benjamin Danger Johnson May 7 '13 at 20:54

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.

• Hey, how would I get the experience from a level using this? @eBusiness – ThePixelPony Aug 31 '14 at 11:34
• I've tried this btw: (int) (Math.pow(10, (Math.ceil(level) - constB) / constA) - constC) – ThePixelPony Aug 31 '14 at 11:49
• @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). – aaaaaaaaaaaa Aug 31 '14 at 12:29