Wheel of fortune clacker using revolute joint

Discuss issues specific to the Flash/AS3 port of Box2D
miner2049er
Posts: 8
Joined: Sun Oct 14, 2012 1:59 pm

Re: Wheel of fortune clacker using revolute joint

Postby miner2049er » Sun Oct 21, 2012 1:10 pm

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.
Attachments
TestWheel.zip
(3.17 KiB) Downloaded 154 times

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Wheel of fortune clacker using revolute joint

Postby irresistible force » Sun Oct 21, 2012 10:39 pm

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.


Return to “Flash”



Who is online

Users browsing this forum: No registered users and 1 guest