[SOLVED] Math question

Hi :slight_smile:

I have created a score bar with two objects:
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 :confused:

Ok, I don’t want to post just some question (your post is some days ago) :smiley: , 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 :

I made a mistake, I was talking about this formula (with 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 :
Capture d'écran de 2015-06-20 19-12-37.png

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 :slight_smile:

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 :slight_smile:

Thanks again for the replies :slight_smile:

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!