Sergozh
Sergozh

Reputation: 11

Moving box2d body ball

How can I move body ball in box2d like a volleyball without accelerating or dumping (with a constant speed).

Do I need a special formula for this?

Upvotes: 1

Views: 958

Answers (1)

Tiago Almeida
Tiago Almeida

Reputation: 14237

In Box2D you move an object with forces. You can apply impulses or a linear force.

You can apply a impulse doing:

myBody->ApplyForce( force, myBody->GetWorldCenter() );

Or a force by doing:

myBody->ApplyForce(force, myBody->GetWorldCenter());

Note than a force is a b2Vec that you can construct doing:

b2Vec force = b2Vec2(0,50);

This force will only push the body up.

If you need a parabolic trajectory then you can create a force that has the component x and y greater than 0:

b2Vec force = b2Vec2(50,50);

Then the physics engine will do the rest.

You can also move to a specific position although I dont advice you to do that.

If you want more information about forces then follow this link.

Upvotes: 1

Related Questions