Need help with bouncing animation

Hi everyone,

I’m currently working on a slot game and what I’m trying to achieve is that once the reels stop spinning, the symbols bounce a little bit up and down before they come to a full stop.

In my code, this method currently handles the stopping of the reels:

if(stopInitiated) {
           speed= 0;
}

This currently just sets the speed of the reels to 0 directly. If the value for float speed is negative, the reels move up and if the value is positive the reels move down. Is there a way to manipulate the value for speed such that a nice little bounce effect is created ?

I tried using this example script for EasingFunction but I don’t exactly understand how the methods work.

I tried:

speed =  EasingFunction.Spring(-0.10f, 0.00f, 0.50f);

and

speed =  EasingFunction.EaseOutBounce(-0.10f, 0.00f, 0.50f);

However, the only thing that happens is that as soon as the stop is initiated, the reel just start spinning upwards forever.

Appreciate your help !

There are visualizations over on easings.net that can be helpful. ( Click on a graph for several ways of seeing it visualized, over on the right. )

As you go from 0 to 1, you progress over the curve following the pattern of the curve. You can progress from 0…1 at whatever speed makes sense for you, and as you reach one you reach the end of the curve.

1 Like

What I forgot to mention is that I’m working within the Update() method.

The actual code is more like this:

private void Update(){
if(stopInitiated) {
speed =  EasingFunction.EaseOutBounce(-0.10f, 0.00f, 0.50f);
}
}

Maybe, since it’s within Update(), the speed for the reels is being reset to the initial value everytime…
This is I think why the reels keep spinning forever and don’t stop. Maybe someone could show me an example of how they would implement an Easing function in this case.

Like I said, your help is very appreciated

I’m not familiar with the exact library you’re using but these easing functions are almost always:

float result = SomeEasing(startValue, endValue, zeroToOneValue);

So it looks like you’re giving it a constant zeroToOneValue, which is what’s throwing everything off.

But additionally, start/end isn’t probably what you want. Let’s say you want to get the speed from 0…5 then back from 5…0. Well that’s two easings, one going up and another going down.

Breaking that apart:

You want to go up from 0…5 over zeroToOneValue1 = timeElapsed1/duration1
then go back down from 5…0 over zeroToOneValue2 = timeElapsed2/duration2

Or something like that