I’m still trying to figure out how to create a bomb simulation. I have a ball and a bomb, when the ball collides with the bomb the bomb explodes and forces the ball in which ever direction the ball was thrown in.
Right now I am using ApplyLinearImpulse, but I am forced to choose a specific direction. I just need the ball to be forced in which ever direction it was thrown in.
For example,
The ball was thrown at the left top side of the bomb, then the ball is forced up and to the left.
The ball was thrown at the left bottom side of the bomb, then the ball is forced down and to the left.
Basically, it just needs to be a bomb. Could anyone tell me how to do this? I am new to Box2d.
This is what I am using right now.
-(void) explodeBomb
{
b2Vec2 force = b2Vec2(-20,20); // give the direction for the force.
_ballBody->ApplyLinearImpulse(force, _ballBody->GetWorldCenter());
}
You need some math there. Assuming the body’s and bomb’s positions are at
bodyPositionandbombPositionrespectively:Now assuming you want to apply a force of
20units: