Reputation: 1054
I'm following this tutorial: http://www.raywenderlich.com/475/how-to-create-a-simple-breakout-game-with-box2d-and-cocos2d-tutorial-part-12
but at the last part, it shows how we can reduce speed by applying damping on a body
if (speed > maxSpeed) {
b->SetLinearDamping(0.5);
}
Where "b" is a body on the world object.
I'm looking for a way to increase the speed by setting linear acceleration (maybe by applying a force ? I don't really know how to do this)
Anyone can help me ? Thanks in advance
Upvotes: 0
Views: 517
Reputation: 1054
If found a way by applying a force too
b2Vec2 velocity = b->GetLinearVelocity();
if (speed <minSpeed) {
b->ApplyForceToCenter(velocity);
}
Upvotes: 0
Reputation: 13713
You can use :
b2Vec2 force;
force.Set(10.0f, 0.0f);
b->ApplyForce(force, b->GetWorldCenter());
This will set a force on your body on the positive x direction giving you a constant acceleration for you body.
Upvotes: 1