I ran into what is possibly a really easy problem, but I can't seem to find the solution.
The Box2D forums are down, so I'll try my luck here.
I want move a Box2D body in a circular pattern. It's a pretty trivial thing to do.
This works perfectly with SetXForm :
//orbitAngle loops from 0 to 360
float dX = cos( orbitAngle * PI / 180.0 ) ;
float dY = sin( orbitAngle * PI / 180.0 ) ;
b2Vec2 moveVec = b2Vec2( body->GetPosition().x + dX / scale, body->GetPosition().y + dY / scale);
body->SetXForm( moveVec , body->GetAngle() );
The problem is SetXForm doesn't work very well with the outside forces applied to the body.
I know I have to use impulses, however this doesn't produce what I want :
float dX = cos( orbitAngle * PI / 180.0 ) ;
float dY = sin( orbitAngle * PI / 180.0 ) ;
b2Vec2 impulseVec = b2Vec2( 0.2 * dX , 0.2 * dY );
body->ApplyImpulse( impulseVec , body->GetWorldCenter() );
The body makes half circles and never returns to origin.
What is the obvious thing I'm missing?