Specifying force and angle in ApplyImpulse in box2d

Posted by Deepak Mahalingam on Game Development See other posts from Game Development or by Deepak Mahalingam
Published on 2012-10-19T07:07:12Z Indexed on 2012/10/19 11:27 UTC
Read the original article Hit count: 200

Filed under:
|

I need to apply an impulse on a object with a particular force and at a particular angle in Box2d. If I am right the syntax would be the following:

body.GetBody().ApplyImpulse(new b2Vec2(direction, power),body.GetBody().GetWorldCenter());

The problem is my direction is in angles. I found a discussion where it was said that the way we can convert an angle into a vector would be as:

new b2Vec2(Math.cos(angle*Math.PI/180),Math.sin(angle*Math.PI/180));

Now I am not sure how to combine these two. In other words, if I wish to apply a force of 30 units at an angle of 30 degrees at the center of the object, how should I do it?

© Game Development or respective owner

Related posts about JavaScript

Related posts about box2d