2

I'm trying to create spinning shapes floating in space. There is still gravity in the environment, however it should not affect these platform objects because they are static (right?). How can I apply a constant angularVelocity to it though? It doesn't seem to apply when I assign it a value, probably due because it's static.

The simplest example would be a spinning gear, an automated teeter-totter (not influenced by external forces). All I'm trying to make is a spinning rectangle that could interfere with a ball controlled by the user.

Do I need to use Joints to pin it in place? How can I specify the details of not being influenced by the dynamic objects?

Thanks for anyone who has an answer to this!

chamberlainpi
  • 4,854
  • 8
  • 32
  • 63

1 Answers1

0

Actually, found a great resource site showing an example of a few common ones: http://blog.thestem.ca/archives/102

An important thing to notice, a joint is pretty much useless by itself (or even with only a single b2Body attached to it).

It always require two (2) bodies to be associated to it's .body1 and .body2 properties. So in order to "pin" an object to the world / background, you have to create a "dummy" body as one of the two body candidates, while the other would be your desired moving object. The motor speed and torque is the key to make it "spin", as opposed to controlling the angularVelocity or directly manipulating the body's angle in an update method.

var pivotDef:b2BodyDef =    new b2BodyDef();
pivotDef.position.SetV( _b2body.GetWorldCenter() );
_b2bodyPivot =  b2WorldInst.CreateBody( pivotDef );

var jointDef:b2RevoluteJointDef =   new b2RevoluteJointDef();
jointDef.Initialize( _b2bodyPivot, _b2body, _b2bodyPivot.GetPosition() );
jointDef.motorSpeed =       1;
jointDef.maxMotorTorque =   10000000;
jointDef.enableMotor =      true;
jointDef.enableLimit =      false;

var joint:b2RevoluteJoint = b2WorldInst.CreateJoint( jointDef )  as b2RevoluteJoint;

--

Hopefully that saves other Flash physicists some time to figure this one out :)

chamberlainpi
  • 4,854
  • 8
  • 32
  • 63
  • To anyone who wants to see an example how that turned out: http://pierrechamberlain.ca/demo.php?demo=BigPunk_MotorPlatforms&folder=others – chamberlainpi Feb 24 '11 at 18:55
  • EDIT: Replaced 'GetLocalCenter()' by 'GetWorldCenter()'. Seems more reliable for pin-pointing the center of bodies. – chamberlainpi Feb 25 '11 at 18:28