1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Rotating a Wheel of Fortune

Discussion in 'Programming' started by M4nu, Feb 10, 2019.

  1. M4nu

    M4nu Member

    Joined:
    Feb 6, 2019
    Posts:
    15
    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;
    }
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,101
    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.
     
    M4nu likes this.
  3. M4nu

    M4nu Member

    Joined:
    Feb 6, 2019
    Posts:
    15
    Would you be able to help out with the code? Or show me how to do it with drag n drop?
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,101
    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).
     
    dannyjenn, M4nu and Bayesian like this.
  5. M4nu

    M4nu Member

    Joined:
    Feb 6, 2019
    Posts:
    15
    Hi! What do you mean by the above? Sorry for being a rookie.
     
  6. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,541
    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.
     
  7. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,101
    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: Feb 21, 2019 at 4:18 PM
    dannyjenn likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice