# [SOLVED] Math question

Hi

I have created a score bar with two objects:
Score_Idle
Score_Fill, where the height starts at 0, and goes up if I get points.

I am looking for a way to limit the growth of Score_Fill, so that it does never exceed the idle object. The ideal case would be normal growth at the start, and slowing down when in the region of the top.

Anyone got ideas? Because Iâ€™m getting tunnel vision, and just trying the same things over and over^^

Could you be a bit more specific? Why the growth speed should slow down? (maybe an aesthetic detail?)
The score bar size depends of the score you have, but they growth in different speeds? If so I think a maximum score is needed

Ok, I donâ€™t want to post just some question (your post is some days ago) , so Iâ€™ll assume:

• A variable â€śscoreâ€ť
• A variable â€śmax_scoreâ€ť
• A Score_Idle and a Score_Fill of same size

To slow down the growth speed, a nice and easy way is to use a quadratic function (or any polynomial function of degree > 1), check this:

Here, the abscissa axis is the score factor = â€śscoreâ€ť/â€śmax_scoreâ€ť, so itâ€™s in the range [0,1]. And the ordinate axis is the sprite scale, of course in the range [0,1].
So, basically, all this theory can be summarized in just one action:

``Do = -pow(Variable(score)/Variable(max_score), 2) + 2*Variable(score)/Variable(max_score) to the scale of Score_Fill``

You can set any math function to get the curve you want, but this is the simplest one. For example, Iâ€™ve adjusted this function (5x/(4x +1)) manually to get a sharper curve:

``Do = (5*Variable(score)/Variable(max_score)) / (4*Variable(score)/Variable(max_score) + 1) to the scale of Score_Fill``

You can test both curves in this example, just de/activate the final events:
ScaleSpeed.zip (2.14 KB)

1 Like

I would use an exponential to have a nice growth at the start decreasing at the end. With this, the score will never be the maximum possible score but will get closer and closer.

ln(x) has a nice growth too, of course you have to adjust it: ln(x) + n has the real root at e^-n

ln(1+x) would be better if you want to have only positive values.

OR for the exponential :

``f(t)=MAX * (1-exp(-gamma*t))``

gamma can be ajusted : f(t) will be at approximately 0.95 * MAX when t=5*gamma
MAX is the maximum value (that will never be reached).

Example :

The difference between ln(1+x) and f(t)=MAX * (1-exp(-gamma*t)) :

• ln(1+x) doesnâ€™t converge when x approach +infinity (there is no maximum)
• f(t)=MAX * (1-exp(-gamma*t)) converges to MAX when x approaches +infinity (and it canâ€™t go further than MAX)
1 Like

Oh my God thanks for the replies

Yes, it is purely aesthetic detail, as I donâ€™t want the score bar to expand beyond the background image, as it will grow into the areas of the game it should not.

As for now, I was using the following function:

``` Variable(Score)/(100*log(Variable(Objective))) ``` which kinda works, but still would exceed if the results of the game are very good^^ I will try your suggestions, and will keep you informed

Thanks again for the replies

OOOOh yes, the exponential function works like a charm, although I had to modify it a bit for it to do what I want:

In this case, I do not use the MaxScore, but the maximum height, which apparently is 1^^ so the formula looks like thus:

``Do = (1-exp(-0.02*Variable(Score))) to the height's scale of Score_Fill``

Thanks a bunch for your help guys!