Rotating a Wheel of Fortune

M4nu

Member
Greetings to the GMC!

I'm looking into spinning a wheel of fortune with the space bar. I got the constant rotating speed using image_angle and a smooth but rather sudden slowdown of the rotation. As I'm a rookie with the coding, I'm looking for advise on what to do here to have a more realistic rotation. How would I use friction or physics to get a realistic rotation movement and slowdown of speed? Basically I want it to have a more delayed slowdown than what it is now. Otherwise it would be cool if the speed increases the longer you hold down space bar and when you release it, the slowdown is relative to the speed of rotation. I would be appreciative of both coding advise for beginners and of advise on drag n drop functions.

Here is the code that I used:

//CREATE EVENT
rspeed = 20; //the speed of rotation, how fast it rotates
Point_dir = 0; //the variable that will store what direction to rotate to
Is_Rotating = 0; //is it rotating, used in the STEP event to rotate the object

//KEYBOARD SPACE EVENT
Point_dir = image_angle + 45; //the angle to rotate to, add 45 degrees to current angle
Is_Rotating = 1; //set to true

//STEP EVENT
if (Is_Rotating == 1) //if its set to rotate the object
{
image_angle += sin(degtorad(Point_dir - image_angle))*rspeed;
}
 

TheouAegis

Member
You could figure out the angle difference-to-time rates yourself in an array.

Friction is the same as gravity. So every step increase the angle by a variable, decrease that variable by a small amount, and check if the spin speed is less than 0.
 

TheouAegis

Member
Create event:
Create a variable spin_speed set to 0.
Create a variable spin_friction set to something like 1/2.

When you want to spin the wheel, set spin_speed to some angle like 90.

Step event:
Check if spin_speed is greater than 0,
then start a block (open curly bracket in gml),
then set image_angle relative to spin_speed (in gml, it's if spin_speed>0 image_angle+=spin_speed),
then set spin_speed relative to -spin_friction (spin_speed-=spin_friction),
then check if spin_speed is less than or equal to 0,
then another start block,
then get the number off the wheel,
then end block,
then end block (because you have two start blocks, you need two end blocks).
 

NightFrost

Member
You know what angle the wheel has stopped at, so you can tell by that what number is at the top. In code, you'd use an array or ds list to store that information, but I don't know how DnD handles that stuff.
 

TheouAegis

Member
You can make the array in the create event using a bunch of Set Variable actions. Call the variable WheelSlot. You make it an array by putting ”[0]" after it, increasing the number in the brackets for each one. E.g.:
Set variable WheelSlot[0] equal to 4
Set variable WheelSlot[1] equal to 2
Set variable WheelSlot[2] equal to 3

Edit: Slots are numbered counterclockwise.

You need to first figure out how many degrees each slot on the wheel takes up. Divide 360 by the number of slots. So if you had 10 slots on the wheel, each slot would take up 36 degrees.

Set a variable spinValue
to "image_angle div d" where d is the number you calculated.

The result of the spin is thus WheelSlot[spinValue].
 
Last edited:
Top