How to apply constant force on Box2D?

I am making Box2d game for iPhone. I need to use force on the body, which represents my main character. The body is actually a rectangle at the top of a circle connected by a revolving joint. I use this as a skeleton for my character who needs to work through the game (any suggestions or feedback about this will be appreciated too).

I need a force that needs to be applied continuously so that it does not move. What would be the best way to do this?

I am currently applying linear velocity inside the tick method.

_world->Step(dt, 10, 10); if(gamestarted) { b2Vec2 force = b2Vec2(6, -3); _bottomBody->SetLinearVelocity(force); } 

But will this force restrain and accelerate the body?

+4
source share
1 answer

Seems simple:

 _bottomBody->ApplyForce(force, _bottomBody->GetPosition()); 

If you apply this force at every step, the body will accelerate in the direction of the force vector.

+6
source

Source: https://habr.com/ru/post/1348135/


All Articles