Wheel of fortune clacker using revolute joint

I am using a revolute joint to act as a Wheel of Fortune "clacker" or whatever the thing is called that gets pushed by the pins as they spin around (which are box2d bodies being rotated on an EnterFrame.) I would like to model the real-world device which has the clacker springing back to its original position after the pin has passed by. Does anybody have any advice on how I might go about this, or can point me in the right direction?
You can use a distance joint to push the clacker back to the center position, with frequency and damping ratio set to make it springy.
irresistible force wrote:You can use a distance joint to push the clacker back to the center position, with frequency and damping ratio set to make it springy.


Thanks for the reply. So I created a couple of bodies, and added a distance joint between them. But when knocked by one of the rotating pins both bodies are thrown about. How can I get one of the bodies to act like the clacker, and effectively pinned to the wall? (One of the bodies will be invisible.) If someone can provide a few more details it would be much appreciated.
Both the wheel itself and the clacker will both be joined to a static 'ground' body with revolute joints. The distance joint will be between the clacker and the ground.

Some similar situations:
viewtopic.php?f=3&t=7545
http://box2d.org/forum/viewtopic.php?f=3&t=7211&p=31810
I'm not using a joint on the wheel - that is just an array of box2d bodies (for the pins) that I am positioning manually and rotating around a centrepoint using trigonometry.

Not too clear on what you say in the last post:

"clacker will both be joined to a static 'ground' body with revolute joints"

then

"distance joint will be between the clacker and the ground"

Why two joints?
Hmm... it sounds like you are totally working against the purpose of having a physics engine.
Two joints for the clacker because
- the revolute is used to pin it to the wall so it turns around a fixed position and doesn't fall to the ground 😉
- the distance joint is used to to make it springy and return to a specific position when not being 'clacked'
I should have mentioned that I'm assuming the revolute will not have any motor enabled, so without the distance joint it would flap around freely.

I had been planning to make a wheel exactly like this as an update for my iPhone 'Lottomixer' app, so when I saw this thread I went ahead and made the underlying physics, because I would need to do it sometime anyway, and also because I could give an answer that I had actually confirmed 🙂
Naturally I made it with the editor I have been working on. The editor is not quite complete and there is no importer to get the data into Flash yet, but if it helps, you could take a look at the scene I made. You would at least be able to play around with variables to see how they affect the behavior.
You'll need to get the editor: http://www.iforce2d.net/rube
And the scene file is here: http://www.iforce2d.net/lottowheel.rube

If anyone wants to actually use this scene in their own app that's fine, but bear in mind that I will also be using it in my app eventually, and I don't want anyone complaining that I copied it from them.
Great stuff, thanks.

Have downloaded the app and data file lottowheel.rube, but am getting the following error when it is run:

Could not load image file '/home/chris/projects/lottowheel/wheel.png'

I see that path and filename inside the lottowheel.rube but not sure what size png is needed to replace with.
It sounds like you are trying to run the script snippet in the script panel? I meant to delete that before uploading, sorry. You can ignore it.
What you need to do is open a player view, with either the red arrow in the toolbar, or Ctrl-R.
To see the attributes for things in the scene, use the B, F, J, V keys to switch between editing bodies, fixtures, joints and vertices, then select them to view their properties in the properties panel.
The documentation is still being worked on I'm afraid 🙂
With your instructions I'm able to run it. RUBE looks to be an excellent tool.

I see what you were saying earlier... I was creating an individual box2d body for each pin, where actually a fixture per pin would suffice inside one body for the wheel.

As I'm unable to export code, I went about typing up the box2d parameters to replicate the scene (see source below) but the wheel keeps falling over.

Any advice on where I might be going wrong?

Code: Select all

var i:int;

         var radius:Number = 100;
         
         // Set Text field
         Main.m_aboutText.text = "Wheel";   
               
         var bodyDefClacker:b2BodyDef = new b2BodyDef();         
         
         bodyDefClacker.type = b2Body.b2_dynamicBody;
         bodyDefClacker.position.Set(400 / m_physScale, 100 / m_physScale);
         
         var bodyClacker:b2Body = m_world.CreateBody(bodyDefClacker);
         
         var fixtureDefClacker:b2FixtureDef = new b2FixtureDef();
         
         var box:b2PolygonShape = new b2PolygonShape();
         box.SetAsBox(5 / m_physScale, 20 / m_physScale);
         fixtureDefClacker.shape = box;
         fixtureDefClacker.density = 5.0;
                  
         bodyClacker.CreateFixture(fixtureDefClacker);      
         
         /*
         
         var bodyDefGround:b2BodyDef = new b2BodyDef;         
         bodyDefGround.type = b2Body.b2_staticBody;                  
         var bodyGround:b2Body = m_world.CreateBody(bodyDefGround);
         
         
         */         
         
         var bodyGround:b2Body = m_world.GetGroundBody();
         
         var bodyDefWheel:b2BodyDef = new b2BodyDef();         
         
         bodyDefWheel.type = b2Body.b2_dynamicBody;
         bodyDefWheel.position.Set(400 / m_physScale, 200 / m_physScale);
         
         var bodyWheel:b2Body = m_world.CreateBody(bodyDefWheel);
         
         for (i = 0; i < 16; i++)
         {         
            degrees = (i * (360 / 16)) % 360;            
            // angle = i * ((Math.PI * 2) / 16);            
            
            radians = degrees * Math.PI / 180;
            
            posX = (Math.cos(radians) * radius);
            posY = (Math.sin(radians) * radius);
            
            var fixtureDef:b2FixtureDef = new b2FixtureDef();
         
            var shapeCircle:b2CircleShape = new b2CircleShape(5 / m_physScale);
            
            shapeCircle.SetLocalPosition(new b2Vec2(posX / m_physScale, posY / m_physScale));            
            
            fixtureDef.shape = shapeCircle;
            fixtureDef.density = 1
               
            bodyWheel.CreateFixture(fixtureDef);      
         }         
         
         var rjd1:b2RevoluteJointDef = new b2RevoluteJointDef();                  
         rjd1.Initialize(bodyGround, bodyWheel, new b2Vec2(100.0 / m_physScale, 500 / m_physScale));         
         rjd1.enableMotor = false;
         rjd1.maxMotorTorque = 0;
         rjd1.motorSpeed = 0;
         rjd1.enableLimit = false;
         rjd1.collideConnected = false;
         rjd1.lowerAngle = 0;
         rjd1.upperAngle = 0;
         m_world.CreateJoint(rjd1);      
         
         var rjd2:b2RevoluteJointDef = new b2RevoluteJointDef();                  
         rjd2.Initialize(bodyGround, bodyClacker, new b2Vec2(100.0 / m_physScale, 500 / m_physScale));         
         rjd2.enableMotor = false;
         rjd2.maxMotorTorque = 0;
         rjd2.motorSpeed = 0;
         rjd2.enableLimit = true;
         rjd2.collideConnected = false;
         rjd2.lowerAngle = -45;
         rjd2.upperAngle = 45;
         m_world.CreateJoint(rjd2);
         
         var rjd3:b2DistanceJointDef = new b2DistanceJointDef;         
         var anchorA:b2Vec2 = new b2Vec2(500.0 / m_physScale, 100 / m_physScale);
         var anchorB:b2Vec2 = new b2Vec2(400.0 / m_physScale, 100 / m_physScale);                  
         rjd3.Initialize(bodyGround, bodyClacker, anchorA, anchorB);         
         rjd3.dampingRatio = 0.1;
         rjd3.frequencyHz = 3;         
         rjd3.length = 5;         
         rjd3.collideConnected = false;         
         m_world.CreateJoint(rjd3);   
At a guess, I would suspect it's because the wheel is centered at 400,200, and the revolute joint for it is at 100,500.

If you're taking the values from the properties in RUBE, it might be better to just set the bodies and local anchors for the joints directly instead of using the Initialize function which does some other position adjustments you're probably not wanting here.

Original thread: https://box2d.org/forum/viewtopic.php?t=8880