Sign in to follow this  

Spinning a wheel and stopping at a given angle

Recommended Posts

Lets say I have a 2D circle that represents a Party Wheel. The circle is divided into several pie shaped slices of 2 different sizes. The idea is that the player spins the wheel and after a couple of rotations it eventually slows down and stops on a specific slice. So, my question is, once the wheel is spinning, how do I calculate the amount of resistance needed to slow the wheel down and stop on the correct slice? Currently, I just track the speed and angle and dampen the speed by a percentage each frame. This definitely slows the wheel down, but calculating the amount of dampening needed to land on a specific slice is difficult. I'm open to other approaches too. As long as it looks like a spinning party wheel that slowly stops on a given slice, then it fits my needs! Thanks! -- Kory

Share this post

Link to post
Share on other sites
You need a function that describes the way your angle changes over time. For example:

Angle(Time) = Initial_Angle + (Angular_Velocity(Time) * Time)

And you have to think if a function that describes how the Angular velocity changes over time:

Angular_Velocity(Time) = Initial_Angular_Velocity - (Friction * Time)

Substitute the latter into the first and you'll get:

Angle(Time) = Initial_Angle + (Initial_Angular_Velocity * Time) - (Friction * Time ^ 2)

Now we have to define Initial_Angle and Initial_Angular_Velocity:

>> Initial_Angle = 0
>> Initial_Angular_Velocity = 2*pi rad/s (one complete rotation per sec)

Now you only need to define the desired angle to stop on, and the time at which it should stop.

>> Time = 10
>> Angle = 1/4*pi (== 90 degrees)

Now we can solve it:

0 + (2*pi * 10) - (Friction * (2*pi) ^ 2) = 1/4*pi + k*2*pi

Note that i've added "k" to the formula wich denotes the ammount of complete rotations until the wheel is stopped. k can be any natural number (0, 1, 2, etc)

If you want the wheel to stop after 3 rotations on the desired angle, you have to solve for:

0 + (2*pi * 10) - (Friction * (2*pi) ^ 2) = 1/4*pi + 3*2*pi

(20*pi) - (Friction * (2*pi) ^ 2) = 6.25*pi

-(Friction * (2*pi) ^ 2) = -13.75*pi

Friction * (2*pi) ^ 2 = 13.75*pi

Friction = ( 13.75*pi ) / ((2*pi) ^ 2)

Friction = 1.09419....

Hope this makes any sense. :)

Share this post

Link to post
Share on other sites
Thanks for the replies. I've come upon a solution that does what I need. You were both correct, I needed an equation I could solve for the angle, which I knew. However, the real problem was the fact that I was dampening the speed by a percentage each frame, thus giving me some funky exponential function based on the frame number.

Making the resistance linear simplified things and allowed me to solve the equation. Basically, I did this:

1. Calculate the amount of time needed to slow the wheel's speed to zero, from its current speed.
2. Calculate the angular distance traveled in that time.
3. Using that distance and the ending angle, calculate the angle where the wheel needs to start slowing down to land on the given angle.
4. Once the wheel reaches the starting angle, it begins to slow down and eventually stops near the desired angle.

It's not perfect, but it works.



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this