문제

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

도움이 되었습니까?

해결책 2

If found a way by applying a force too

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top