Wheel of fortune clacker using revolute joint

Thanks, I fixed the falling wheel and clacker by inserting correct positions, but now the clacker is giving me additional problems.

PROBLEM 1:

Rather than the RUBE demo's clacker with a limited range of motion, and realistic behaviour, mine is like a wind chime flapping around - and it even rotates in a full circle.

I have attempted to replace the

Code: Select all

rjd2.Initialize(bodyGround, bodyClacker, new b2Vec2(BODY_CLACKER_X / m_physScale, BODY_CLACKER_Y / m_physScale));


as advised with "set the bodies and local anchors for the joints directly instead of using the Initialize function"

but I'm having no luck when I try to do this.

PROBLEM 2:

With the clacker geometry, which I took from the demo:

Code: Select all

var clackerShapePolygons:Array =
         [[
         
            [ -0.130863, -2.17848],            
            [0.130863, -2.17848],            
            [0.288847, 0.0183992 ],
            [0.223228, 0.288349],
            [ -0.223228, 0.288349],
            [-0.288847, 0.0183992 ]            
         ]];      


That initially sits upside down because of the Y increasing up in the demo, whereas Flash has Y increasing down.

So when I flip the sign of all the Y vertices in the data, the clacker fixture appears OK but for some reason there is no collision with the pins.

PROBLEM 3:

After all this is working, like in the RUBE demo, how would I go about spinning the wheel and getting it to land on a predetermined slot/angle?

With a basic non-box2d circle rotating there are a number of ways of doing this, such as with tweening to a certain angle etc but how to do it when physics are involved?

As no random numbers are involved, using the same starting parameters - wheel position, angular velocity given etc. - the wheel will always end at the same spot, but can certain positions be steered to somehow, rather than using trial and error?

Once again assistance is required.

I have attached the TestWheel.as file, which slots into the Box2DFlashAS3 project which is part of the Box2d download.
1. Did you enable limits for the revolute joint of the clacker? Is the distance joint functioning at all?
2. Simply reversing the y values of the vertices will result in a clockwise winding, so you'll need to reverse the ordering of them as well.
3. Spinning the wheel could be done by ApplyAngularImpulse, or ApplyTorque for a few timesteps. Getting it to stop on a pre-determined slot is not trivial. The only sure-fire way to do it would be to run the simulation and see which slot it stopped on, rotate the texture/sprite so that the one you want is chosen, then reset the bodies to the original state and run it again. You might also be able to build a lookup table which holds the starting impulse required to select a slot which is n slots away from the current position, but it may not be very reliable.

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