many apologies if this replicates a previous question - i have looked but nothing seems to address quite what my problem is.
What I'd like to do is set up a point within a world that attracts all other bodies. I've set the world gravity to zero and then variously experimented with ApplyForce and ApplyImpulse but get nothing but errors.
Tried following the example here:
viewtopic.php?f=8&t=1844&hilit=gravity
to no avail.
CODE:
body_def = new b2BodyDef();
shape_def = new b2BoxDef();
shape_def.extents.Set(51,51);
shape_def.friction = 0.2;
shape_def.density = 0.5;
shape_def.restitution = 0.6;
body_def.position.Set(Math.random()*900+50,0);
body_def.AddShape(shape_def);
body_def.userData = new crate();
body_def.userData.name = 'circle';
body_def.userData.width = shape_def.extents.x * 2;
body_def.userData.height = shape_def.extents.y * 2;
addChild(body_def.userData);
the_world.CreateBody(body_def);
body_def.ApplyImpulse(new b2Vec2(6, 4));
which generates the following ERROR:
1061: Call to a possibly undefined method ApplyImpulse through a reference with static type Box2D.Dynamics:b2BodyDef.
Can anyone point me in the right direction as far as correct syntax goes?
What I'd like to do is set up a point within a world that attracts all other bodies. I've set the world gravity to zero and then variously experimented with ApplyForce and ApplyImpulse but get nothing but errors.
Tried following the example here:
viewtopic.php?f=8&t=1844&hilit=gravity
to no avail.
CODE:
body_def = new b2BodyDef();
shape_def = new b2BoxDef();
shape_def.extents.Set(51,51);
shape_def.friction = 0.2;
shape_def.density = 0.5;
shape_def.restitution = 0.6;
body_def.position.Set(Math.random()*900+50,0);
body_def.AddShape(shape_def);
body_def.userData = new crate();
body_def.userData.name = 'circle';
body_def.userData.width = shape_def.extents.x * 2;
body_def.userData.height = shape_def.extents.y * 2;
addChild(body_def.userData);
the_world.CreateBody(body_def);
body_def.ApplyImpulse(new b2Vec2(6, 4));
which generates the following ERROR:
1061: Call to a possibly undefined method ApplyImpulse through a reference with static type Box2D.Dynamics:b2BodyDef.
Can anyone point me in the right direction as far as correct syntax goes?