4

I'm trying to create a wheel of fortune game.

Everything is working fine but I can't find a realistic way to decelerate the wheel rotation speed.

Currently I just tried to do something like this:

    if (spin > 3) spin-=0.030;
    if (spin > 2) spin-=0.020;
    if (spin > 1) spin-=0.015;
    if (spin > 0.5) spin-=0.010;
    if (spin > 0) spin-=0.005;
    if (spin < 0) spin=0;

But of course it's not a very nice approach, and even changing values here and there the result is not really satisfying.

What would be the mathematical function to gradually slow down the rotation?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
devamat
  • 2,293
  • 6
  • 27
  • 50
  • https://physics.stackexchange.com/questions/163721/wheel-slowing-down-with-constant-acceleration – BackSlash Aug 27 '18 at 12:31
  • Maybe related, maybe note, but definitely a very interesting read: https://stackoverflow.com/a/51904555/1531124 – GhostCat Aug 27 '18 at 12:51

2 Answers2

0

You might try the following:

final float DECEL = 0.95;
final float FRICTION = 0.001;
spin = spin * DECEL - FRICTION;

This assumes that this is getting called on a regular time interval. The extra "- FRICTION" is there, so that the wheel will actually stop.

If your drawing loop is getting called with a time delta since the last frame draw, then you would use that to adjust the DECEL and FRICTION parameters. For example, you might have:

final float DECEL = 0.95;
final float FRICTION = 0.001;
// calculate how much the wheel will slow down
float slowdown = spin - (spin * DECEL - friction);

// Apply the frametime delta to that
slowdown *= frameDelta;
spin = spin - slowdown;

This, of course, will take some experimentation with the DECEL and FRICTION parameters.

Edward Dan
  • 134
  • 1
  • 10
Jamie
  • 1,888
  • 1
  • 18
  • 21
0

You could try to model the slowdown by using an exponentially decreasing equation that equals your spin speed. Then stop the spinning wheel by putting a limit on how long it spins (as y=0 is an asymptote in an exponential eq.).

float spinSpeed;  //will track the spinning speed using an equation
double spinTime = 4;  //limits total spin time using an equation

for (i=1;i<=4;i++) {  //will track time in seconds
spinSpeed = math.pow[5.(-i+3)];  //equivalent  to y=5^(-(x-3))
}  //be sure to import math 
Edward Dan
  • 134
  • 1
  • 10