Hi,
I'm using a MouseJoint created as follows. I'm using it to make the body follow the sprite.
and in the update call, I'm doing the following
But this doesn't seem to be moving the body at all. Any ideas on what I'm missing?
I'm using a MouseJoint created as follows. I'm using it to make the body follow the sprite.
Code:
// Define the ground body.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0); // bottom-left corner
b2Body *groundBody = _game.world->CreateBody(&groundBodyDef);
b2MouseJointDef mjd;
mjd.collideConnected = true;
mjd.target = b2Vec2(_pos.x * [Box2DHelper metersPerPoint], _pos.y * [Box2DHelper metersPerPoint]);
mjd.bodyB = self.body;
mjd.bodyA = groundBody;
mjd.dampingRatio = 0;
mjd.frequencyHz = 100;
_mj = (b2MouseJoint *)_game.world->CreateJoint(&mjd);
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0); // bottom-left corner
b2Body *groundBody = _game.world->CreateBody(&groundBodyDef);
b2MouseJointDef mjd;
mjd.collideConnected = true;
mjd.target = b2Vec2(_pos.x * [Box2DHelper metersPerPoint], _pos.y * [Box2DHelper metersPerPoint]);
mjd.bodyB = self.body;
mjd.bodyA = groundBody;
mjd.dampingRatio = 0;
mjd.frequencyHz = 100;
_mj = (b2MouseJoint *)_game.world->CreateJoint(&mjd);
and in the update call, I'm doing the following
Code:
-(void) update:(ccTime)dt {
b2Vec2 pos = b2Vec2( self.position.x * [Box2DHelper metersPerPoint], self.position.y * [Box2DHelper metersPerPoint]);
if(_mj) {
_mj->SetTarget(pos);
}
}
b2Vec2 pos = b2Vec2( self.position.x * [Box2DHelper metersPerPoint], self.position.y * [Box2DHelper metersPerPoint]);
if(_mj) {
_mj->SetTarget(pos);
}
}
But this doesn't seem to be moving the body at all. Any ideas on what I'm missing?