Thanks for the replies, but I'm still stuck with the same problem
Code:
private function CreateHinge2(px:Number, py:Number, pr:Number, pw:Number, ph:Number):void
{
var x = px / Globals.m2p;
var y = py / Globals.m2p;
var r = pr / 2 / Globals.m2p;
var w = pw / 2 / Globals.m2p;
var h = ph / 2 / Globals.m2p;
trace("1");
// BOX
var boxBody:b2BodyDef = new b2BodyDef();
boxBody.position.Set(x, y);
boxBody.type = b2Body.b2_staticBody;
var boxShp:b2PolygonShape = new b2PolygonShape();
var shapeVert:Array = new Array();
shapeVert[0] = new b2Vec2(0.5 * w, -0.5 * h);
shapeVert[1] = new b2Vec2(0.5 * w, 0.5 * h);
shapeVert[2] = new b2Vec2(-1 * w, 0.5 * h);
shapeVert[3] = new b2Vec2(-1 * w, -0.5 * h);
boxShp.SetAsArray(shapeVert, 4);
var my_boxfixt:b2FixtureDef = new b2FixtureDef();
my_boxfixt.density = 0.5;
my_boxfixt.shape = boxShp;
trace("2");
// CIRCLE
var circleBody:b2BodyDef = new b2BodyDef();
circleBody.position.Set(x, y);
circleBody.type = b2Body.b2_staticBody;
var circleShp:b2CircleShape = new b2CircleShape(r);
var my_cirfixt:b2FixtureDef = new b2FixtureDef();
my_cirfixt.density = 0.5;
my_cirfixt.shape = circleShp;
trace("3");
var boxWorldBody:b2Body = Globals.world.CreateBody(boxBody);
boxWorldBody.CreateFixture(my_boxfixt);
var circleWorldBody:b2Body = Globals.world.CreateBody(circleBody);
circleWorldBody.CreateFixture(my_cirfixt);
trace("4");
revJoint.Initialize(circleWorldBody, boxWorldBody, circleWorldBody.GetWorldCenter());
revJoint.enableLimit = true;
revJoint.maxMotorTorque = 1.0
revJoint.motorSpeed = 0.3;
revJoint.enableMotor = true;
var theJoint:b2RevoluteJoint = Globals.world.CreateJoint(revJoint) as b2RevoluteJoint;
/*revJoint.Initialize(circleBody, boxBody, circleBody.GetWorldCenter());
revJoint.lowerAngle = -0.5 * 180;
revJoint.upperAngle = 0.25 * 180;
revJoint.enableLimit = true;
revJoint.maxMotorTorque = 1.0;
revJoint.motorSpeed = 0.0;
revJoint.enableMotor = true;
var theJoint:b2RevoluteJoint = LevelVars.world.CreateJoint(revJoint) as b2RevoluteJoint;*/
}
OK, so what I'm trying to achieve here is:
- a box that joint with a circle that I can pull and rotate
- the circle should stay still, but I can drag and rotate the box freely, with the circle as the center
- but the circle and box must not react from other physical forces (other objects)
I thought revolute Joint should be the answer, but now I think there's either something with my head or my code.
The problem when I used box2D 2.01..
I can achieve what I wanted when I pull the box, but the body reacted when other objects collide with it. Now I'm confused how to ask my question and wondering if I have made myself clear or not
😢 Somebody please help me resolve this? I've got to finish this whole game by tonight..
😮 Thank you in advance