When I have implemented leveling systems I have generally done so in such a way that the user never saw the actual number for the experience requirement, and as such my numbers need not be as “clean” (multiples of 5, 10, etc) and as for the decimals that is easily solved with a built-in rounding method,.
Edit: obviously this was a low level implementation. You asked how we have done it, so that’s how I did it. I’m certainly not recommending that you use my lazy method.
This is code that I wrote for one of my projects. It took me a while to find the right curve and offset for my game. Lots of experimenting by printing for-loops with levels and exp deltas with the commandbar.
local exponent = 3
local lvlOffset = -4
local experienceOffset = -1250
function module.experienceToLevel(exp)
return math.floor(.5+math.floor((exp-experienceOffset)/experienceMultiplier)^(1/exponent)) + lvlOffset
end
function module.levelToExperience(lvl)
return math.floor(.5+((lvl-lvlOffset)^exponent)*experienceMultiplier + experienceOffset)
end
Note: The functions assume that exp is total exp, not the exp until the next level.
Althought its not using math.Floor it is quite effective And it makes it harder to level up each time so you can get to the first few levels easy, and it gets harder and harder (If any one could tell me the math so I could use math.Floor it would be great haha)
Good point. I actually start from Level 1, but then set the target exp to that of the current level.
For example, if you’re:
Level 1, you have to earn ((1(1+1)) / 2)*100 Exp
Level 2, you have to earn ((2(2+1)) / 2)*100 Exp
Level 3, you have to earn ((3(3+1)) / 2)*100 Exp