Help with getting the percentage difference from this level/exp algorithm?

A while ago I was researching for a common level/exp algorithm and I did come across one. The problem is that when I had come to make an EXP bar frame it seems like after a few levels the EXP bar is always close to 1.

The module below is what I came up with, so for example level 1 = 100 EXP and level 2 = 400 EXP, I was trying to make the EXP bar frame by doing the current exp divided by the exp required for the next level however this does not seem to be working. I cannot seem to figure out the math to get the right difference…

(As for this example if level 1 = 100 EXP and level 2 = 400 EXP then 100/400 is already starting with 0.2 instead of 0 in my X scale)

Any ideas?

local module = {}

--Constants
local levelConstant = 0.1
local rebirthConstant = 0.1

--GetLevel(EXP)
--i.e. returning the Level from EXP
function module.GetLevel(EXP)
	local level = levelConstant * math.sqrt(EXP)
	return math.floor(level)
end

--GetEXP(num)
--i.e. returning the EXP from Level
function module.GetEXP(level)
	local EXP = (level/levelConstant)^2
	return math.floor(EXP)
end

return module

(Ref: https://gamedev.stackexchange.com/questions/13638/algorithm-for-dynamically-calculating-a-level-based-on-experience-points)

1 Like

You’re looking for something like this:

local progress = (currentXP - currentLevelXP) / (nextLevelXP - currentLevelXP)

If you were currently at level 30, working towards level 31, then this would be:

local progress = (currentXP - level30XP) / (level31XP - level30XP)
6 Likes