Calculating next upgrade cost

Hello Developers,

So currently I’m trying to calculate what the next upgrade will cost for a player depending on their current level. For example within my game there is a speed upgrade that decided how fast you get in game cash and every time you upgrade it it goes down by 0.1, so if the base speed was 10 and you get a upgrade it is now 9.9. With that in mind how would I go about calculating the next upgrade, lets say it’s 1k for the first upgrade how will I automatically double that to 2k for the next upgrade without storing each upgrade and its cost within a table and just basing it off their current. Here is what I tried but it doesn’t work.
(10 + (10 - Upgrades.Speed)) * 1000

If you are fine with low difference upgrade costs I would go for

local Speed= Upgrades.Speed
local BaseCost = 1000
local UpgradeCost = 1000 * 1.5 * Speed

Preferably I’d like to double the costs as stated within my question, just wondering if its possible.

Oh yes just get the cost before updating the new upgrade cost and multiply it by two.

Converting Levels Into XP & Vice Versa | Jake Lee on Software Perhaps you could look into this , this for experience calculation but you could just change the x , y values to get the way you want.

You can get the incremented amount by storing the initial value in a variable and multiplying it by the difference in initial speed and current.
e.g.

local baseSpeed = 10
local speed = 9.5
local upgradeCost = 1000

local function calculateUpgradePrice()
    return math.abs(baseSpeed - speed) * 10 * upgradeCost
end

The upgrade cost, when the speed is 9.5, would be 5000.

1 Like

Thanks for this, took a long time to get this working and you did it.

1 Like