Question

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

Was it helpful?

Solution 2

If found a way by applying a force too

b2Vec2 velocity = b->GetLinearVelocity();
if (speed <minSpeed) {
   b->ApplyForceToCenter(velocity);
}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top