How can I make an impulse so that point b moves away from point a in box2d/ cocos2diphone

box2d, cocos2d-iphone, ios, math, objective-c

Solution

Try using this:

b2Vec2 impulseB = bodyB->GetPosition() - bodyA->GetPosition();
impulseB /= impulseB.Length();
impulseB *= predefinedScaleValue; // predefinedScaleValue is your velocity
b2Vec2 impulseC = -impulseB;
bodyB->ApplyLinearImpulse(impulseB, bodyB->GetWorldCenter());
bodyC->ApplyLinearImpulse(impulseC, bodyC->GetWorldCenter());

I hope it's clear what's going on here. If not, just ask :)

Problem

I'm applying an impulse on a box2d object with something like this: ``` b2Vec2 impulse = b2Vec2(4.0f, 15.0f); body->ApplyLinearImpulse(impulse, body->GetWorldCenter()); ``` I know this is probably high school math, and I promise I have made efforts to discover this for myself; please forgive my ignorance. If I have objects a, b and c - and object a is at the midpoint of b and c, how can I create a Box2D impulse so that objects b and c move away from a at velocity v?

Original source