SOLVED Wheel of Fortune Question

ScaryPotato

Member
Wheel.jpg

Video of spinning wheel



GML:
/// @description Creating multiple spinning instances

phy_position_x = room_width/2;
phy_position_y = room_height/2;

col = make_colour_rgb(217, 87, 99);

render_flags = phy_debug_render_shapes | phy_debug_render_joints | phy_debug_render_coms | phy_debug_render_obb;

var i;

for (i = 0; i < 16; i += 1)
   {
        var
        locationX = lengthdir_x(175, (22.5*i)+11.25),
        locationY = lengthdir_y(175, (22.5*i)+11.25),
       
        pocketMaker = instance_create_depth(x+locationX, y+locationY, -1, oPocket),
        pocketFix = physics_fixture_create();
 
        pocketMaker.phy_rotation = 78.75 - (22.5*i);//Setting oPocket instance angles
       
         switch (i)//Setting point values for different oPocket instances
       {
           case 0:
           case 8:
           pocketMaker.pointValue = 5;
           break;
     
           case 1:
           case 9:
           pocketMaker.pointValue = 10;
           break;
     
           case 2:
           case 10:
           pocketMaker.pointValue = 15;
           break;
     
           case 3:
           case 11:
           pocketMaker.pointValue = 20;
           break;
     
           case 4:
           case 12:
           pocketMaker.pointValue = 25;
           break;
     
           case 5:
           case 13:
           pocketMaker.pointValue = 50;
           break;
     
           case 6:
           case 14:
           pocketMaker.pointValue = 75;
           break;
     
           case 7:
           case 15:
           pocketMaker.pointValue = 100;
           break;
        }
         
        physics_fixture_set_box_shape(pocketFix, 21, 1);
        physics_fixture_set_density(pocketFix, 0);
        physics_fixture_bind(pocketFix, pocketMaker);
        physics_fixture_delete(pocketFix);
   
        physics_joint_revolute_create(id, pocketMaker, phy_position_x, phy_position_y, 0, 0, false, 1000, 0.2, true, false);
       
        var
        locationXX = lengthdir_x(176, 22.5*i),
        locationYY = lengthdir_y(176, 22.5*i),
       
        blockMaker = instance_create_depth(x+locationXX, y+locationYY, -1, oBlocker),//Creating oBlocker
        blockFix = physics_fixture_create();
       
        blockMaker.phy_rotation = 90 - (22.5*i);//Setting oBlocker instance angles
       
        physics_fixture_set_box_shape(blockFix, 21, 1);
        physics_fixture_set_density(blockFix, 0);
        physics_fixture_bind(blockFix, blockMaker);
        physics_fixture_delete(blockFix);
   
        physics_joint_revolute_create(id, blockMaker, phy_position_x, phy_position_y, 0, 0, false, 1000, 0.2, true, false);
   }
I've been working on this for a little while, but don't have any experience with using physics in gamemaker, so I hope someone can help me out with this!
The code creates a slowly spinning wheel, made up of 16 pink bars, and 16 dark shapes.

Depending on the torque (1000) and motor speed (0.2) values used in physics_joint_revolute_create, the two types of instances seem to really bounce around and overlap each other.
Is there a way to make the two instance types move cohesively?
And is there a way to smoothly decrease/stop the spin of the instances, like the big wheel thing on Wheel of Fortune?

Thanks in advance for any help figuring this out!

~Edit~ Added link to video of wheel in motion
 
Last edited:

woods

Member
i know nothiong of the physics in GMS ... but i did stumble upon this in the big book ;o)


Angular Damping: If you think about any rotating object in the "real world", unless it has a motor or is in space, it slows down over time due to the influence of external forces (like friction with the air around it). We can use set this option to simulate this effect and reduce the velocity of rotation of instances in the physics world, as, without it, any rotating instance would continue to rotate infinitely.


looks like the spot to start ;o)
wish i was more help
 

ScaryPotato

Member
Hey woods, the way I understand it, my setup uses a motor to spin the instances with this code:

physics_joint_revolute_create(id, pocketMaker, phy_position_x, phy_position_y, 0, 0, false, 1000, 0.2, true, false);

Where 1000 is the torque value, and 0.2 is the speed of the motor. I tried adjusting the angular_damping setting on the chance it would have an effect, but it didn't (likewise, changing the torque to 1 doesn't change the herky-jerky motion)

Thanks for making me look at the basic settings though, the solution could be a simple one that I'm completely looking over!
 

woods

Member
often times we are looking too hard.. KISS(Keep It Simple Stupid) is one of your best friends...

i donno... (is above me ;o) ..just shooting in the dark for ya.. maybe spark an idea)
maybe after you get the wheel spinning, lerp the torque-1000?
 

ScaryPotato

Member
Create Event
Code:
randomize();
revolve = 5;//Set speed for spin
revolveMinus = random_range(0.003, 0.055);//Choose how much to slow spin down

var
xx = room_width/2,
yy = room_height/2;

for (var i = 0; i < 16; i++;)
    {
        var
        locationX = lengthdir_x(175, (22.5*i)+11.25),
        locationY = lengthdir_y(175, (22.5*i)+11.25),
        
        pocketMaker = instance_create_depth(xx+locationX, yy+locationY, -1, oPocket),
        pocketFix = physics_fixture_create();
        
        pocketMaker.phy_rotation = 78.75 - (22.5*i);//Setting oPocket instance angles
        
        physics_fixture_set_box_shape(pocketFix, 21, 1);
        physics_fixture_set_density(pocketFix, 0);
        
        physics_fixture_bind(pocketFix, pocketMaker);
        physics_fixture_delete(pocketFix);   
        
        revJointA[i] = physics_joint_revolute_create(id, pocketMaker, xx, yy, 0, 0, false, 1, revolve, true, false);
    }
Step Event
Code:
revolve -= revolveMinus;

for (var j = 0; j < 16; j++;)
    {
        if physics_joint_get_value(revJointA[j], phy_joint_motor_speed) > 0//if not stopped
            {
            physics_joint_set_value(revJointA[j], phy_joint_motor_speed, revolve);//gradually slow down
            }
    }

So, after racking my brain for far too long, it occurred to me that the key was controlling each copy of the revolute joint, which turned out to be as simple as using a for loop in the Step Event. Major headache getting to the solution, but super happy to get it working!

woods - Your advice was totally on point, so thank you!
 
Top