Mathematical formula to halve the amount each doubling.

Talk about your skill passion! Ask questions, get feedback, post something cool!

Moderator: samw3

User avatar
Posts: 1279
Joined: Wed Oct 21, 2009 11:43 pm
Location: Finland

Mathematical formula to halve the amount each doubling.

Postby bugala » Thu Aug 28, 2014 6:39 am

I am making this game, where there is system to upgrade buildings with money.

System is following, if you fund the building 100 percent, you get it done in 5 (game) weeks.

Lets suppose 100 percent funding is 100 USD.

However, if you want to speed up the building time, you can put additional money into it, but you can never reach more speed than 200 percent (and actually reaching that is impossible).

The system is following.

Suppose you need 100 USD to reach 100 percent.

You put another 100 USD more, and you can reach 150 percent.

If you after that put even another 100 USD (that is 300 USD in total), you can reach up to 175 percent.

next 100 USD again, will make it go to 187.5.

By other words, each 100 USD after the 100 percent, always results only in half the power before.

But how do I implement this mathematically. That suppose someone puts 135 USD of money in to building that building, how fast should it be building (percentage wise) then?
User avatar
Posts: 307
Joined: Tue Aug 31, 2010 5:39 am

Re: Mathematical formula to halve the amount each doubling.

Postby brownboot » Fri Aug 29, 2014 8:50 am

Exponential Decay: ... decayl.htm

//fake C# go

TempInvestment //variable for how much you're adding this time
NewInvestment // the amount you're adding to the total
BuildInvestment //total you've invested so far
BuildCost // how much you need to invest to reach 100% build rate

TempInvestment = NewInvestment * 0.5 ^((BuildInvestment + NewInvestment) - BuildCost);
BuildInvestment += TempInvestment;

You'll need to make it a little more complicated so it checks to see if the new total is under 100% or if it goes over to set it to 100% then calculate the exponential gain on the leftover.

You'll also have to calculate the build rate based on the current investment; something like...

BuildRate //How fast you're building
BuildProgress // How much has been built so far
Time.time //how much time since the start of the game
startTime //when you started building

BuildRate = BuildInvestment / BuildCost; // 100% investment = rate of 1.
BuildProgress += (Time.time-startTime)*BuildRate;


Who is online

Users browsing this forum: No registered users and 4 guests