Search code examples
performancecocos2d-iphonegame-physicsacceleration

increase speed/velocity, cocos2D


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


Solution

  • If found a way by applying a force too

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