1
votes

i'm losing myself in this...

Situation: Working on a game in cocos2d with box2d and I have a ropejoint between one fixed body and one dynamic body.

When I drop the dynamic body is swings from left to right and then from right to left due to the gravity in the world.

The problem: The swings are getting shorter and shorter till finally the dynamic body hangs still beneath the fixed body. This is normal behavior but I need it to keep swinging.

My thoughts: I think I need to apply a tangential force to the ropejoint in the direction of the swinging but how to do this is a mystery for now :)

2

2 Answers

0
votes

Try setting the damping factor of the rope joint to zero

ropeJointDef.dampingRatio = 0.0f;

Hope it helps!

0
votes

Here is a little code that should help you with your little problem

bool YourClass::init(){

CCCallFunc *swingL = CCCallFunc::create(this,callfunc_selector(YourClass::swingLeft));
CCDelayTime *delay = CCDelayTime::create(5);
CCCallFunc *swingR = CCCallFunc::create(this, callfunc_selector(YourClass::swingRight));

this->runAction(CCRepeatForever::create(CCSequence::create(swingL,delay,swingR,NULL)));

}   



void YourClass::swingLeft(){

    b2Body *dynamicBody = get your body from b2world;
    dynamicBody->SetLinearVelocity(b2Vec2(-10, 0));//set velocity of the swing

}

void YourClass::swingRight(){

    b2Body *dynamicBody = get your body from b2world;
    dynamicBody->SetLinearVelocity(b2Vec2(10, 0));//set velocity of the swing

}