Throwing a bomb in LibGDX Box2D

840 Views Asked by At

I am trying to create game where somenone throw a bomb . I am wondering how I can have an bomb react in a way that is represented by the following picture : enter image description here

Is there are any tools in Box2D that can help me achieve this? I have already created bomb which are effected by gravity and forces. But I don't know how I need to throw the bomb?

Here how I created the bomb

Body bomb;
BodyDef bdef = new BodyDef();
FixtureDef fdef = new FixtureDef();

CircleShape bombBall = new CircleShape();

bdef.type = BodyType.DynamicBody;
fdef.restitution = 0.4f;

bigBall.setRadius(1f/PPM);
bdef.position.set(0/PPM, 10f/PPM);

fdef.shape = bombBall;
fdef.density = 0;

ball = world.createBody(bdef);
ball.createFixture(fdef);

And here in my render methot I apply linear Impulse

ball.applyLinearImpulse(.09f, 0.09f, ball.getPosition().x, ball.getPosition().y, true);
1

There are 1 best solutions below

4
nikoliazekter On BEST ANSWER

As it was mentioned in comments you need to apply linear inpulse to your bomb. It's pretty easy thing. You only need to make something like this

body.applyLinearImpulse(your_x_impulse,your_y_impulse, body.getPosition().x, body.getPosition().y, true);

where your_x_impulse and your_y_impulse are mass*velocity x and y accordingly.