Continuously Rotating Object

Hello all, I'm currently in the process of trying to get my head around 'joints' and 'motors' as used in Box2D... and not getting very far haha I really need more examples!

I'm just trying to get the triangle called 'rotatingTriangle' to rotate constantly about it's centre of mass as if it was pinned to the background and being driven by a little motor... but it's not moving at all. I think I have attached it to the 'world object' but I'm not sure about this either so I could be wrong. I realise the lower angle and upper angle lines of code are probably unnecessary but I've just copied and pasted from the Manual (because I don't know what anything does) and was planning on tweaking/removing lines of code to get the effect I was wanting.

var jointDef:b2RevoluteJointDef = new b2RevoluteJointDef();

jointDef.Initialize(gameWorld.GetBodyList(), rotatingTriangle, rotatingTriangle.GetWorldCenter());
jointDef.lowerAngle = -0.5 * b2Settings.b2_pi; // -90 degrees
jointDef.upperAngle = 0.25 * b2Settings.b2_pi; // 45 degrees
jointDef.enableLimit = true;
jointDef.maxMotorTorque = 10.0;
jointDef.motorSpeed = 1.0;
jointDef.enableMotor = true;

One other thing that could be causing a problem is that the 'rotatingTriangle' is a static object (e.g. 0 mass), but if I make it non-static the triangle just falls down (but doesn't tip over... it stands up on it's point).

Any help here would be much appreciated, I've been looking in the documentation/manual/etc but I can't make head nor tail of how to correctly set up joints, etc...
code is 100% except for this line:

jointDef.Initialize(gameWorld.GetBodyList(), rotatingTriangle, rotatingTriangle.GetWorldCenter());

if your looking to attach to the background, its:
gameWorld.GetGroundBody ()

and im not sure about

rotatingTriangle.GetWorldCenter()

i would personally just use

rotatingTriangle.GetPosition ()
Hey! Thanks for your help... but I've made the suggested changes and it's still doing the exact same thing and not rotating at all :/

I even tried using GetPosition() instead of GetWorldCentre() and nothing different happened. Any other ideas? (Incidentally the reason I'm using GetWorldCentre() is because the triangle is defined from its upper left corner, and I don't want it to rotate around this)

I really need to get this working asap, I'm running out of time for a deadline... and the documentation on joints really doesn't explain anything at all...
Right I've got it now, the problem was that I didn't have this line:

var joint_added:b2RevoluteJoint = gameWorld.CreateJoint(jointDef) as b2RevoluteJoint;

to actually add the joint to the world :/ SURELY the manual should make some mention of this? *sigh*
Dinkyfish wrote:
Right I've got it now, the problem was that I didn't have this line:

var joint_added:b2RevoluteJoint = gameWorld.CreateJoint(jointDef) as b2RevoluteJoint;

to actually add the joint to the world :/ SURELY the manual should make some mention of this? *sigh*


actually, it does mention it in the joint factory section, but i do agree the manual does need some work. I'm sure that when 2.1 gets officially released its manual should be a bit better.

Glad you have it working though.
Dinkyfish wrote:
Right I've got it now, the problem was that I didn't have this line:

var joint_added:b2RevoluteJoint = gameWorld.CreateJoint(jointDef) as b2RevoluteJoint;

to actually add the joint to the world :/ SURELY the manual should make some mention of this? *sigh*



From the manual...


Code:
var jointDef:b2RevoluteJointDef = new b2RevoluteJointDef();
jointDef.body1 = myBody1;
jointDef.body2 = myBody2;
jointDef.anchorPoint = myBody1.GetCenterPosition();

var joint:b2RevoluteJoint = myWorld.CreateJoint(jointDef);

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