# How to Model the Wheels of a Slot Machine

Recently, in my IT class we had to create our own simple games as an exercise in programming. What I chose to make was a casino with a lot of slot machines in Unity. It was mainly an exercise in using Unity as I have little experience working with it. To demonstrate what I’m talking about, I made a small video showcasing the slow machines:

https://www.youtube.com/watch?v=TCuDuJK2zQQ

Now, what I want to talk about in this post is how to make the wheels of the slot machine stop at the right entries, so that we can easily program the slot machines to do what we want. Which means we can have a function:

rotateAndStopAtAngles(ANGLE_1, ANGLE_2, ANGLE_3);

Let’s assume that the wheels are already in motion and are travelling with an angle velocity of . Let’s also assume that the wheels are affected by a constant acceleration when they’re stopping. This means that their time dependent angle velocity can be described as:

Where is the initial velocity of the wheel and is the deceleration. Obviously we want the wheels to stop spinning, so we want to find the time which satisfies:

Which means we get the following expression for :

Now, what we want to find now is the angle where we start the deceleration of the wheel. Let be the angle we want to wheel to stop on. Obviously, the total angle breadth travelled when decelerating is:

Now, obviously we want to satisfy:

Or written out in full:

Which allows us to get the following expression for :

And as you can see in the above video, it works! This is what I love about math – it’s such a powerful language for describing the world. Although, due to technical issues (*cough cough* floats) and due to the fact that computers work with discrete units rather than continuous units it doesn’t stop at *exactly *the right angle, but this is easily mitigated as you can see in the above video by sliding in at low speed to get it to stop just right.