I have a player box2d object on screen, who should be controlled by two buttons, one left, and one right. When you press the right button, the player should move right, but when you press the left button, the player should immediatly stop moving right and move left. This should also happen vice versa.
I tried to do this to move right,
b2Vec2 impulse(4, 0);
body->ApplyLinearImpulse(impulse, body->GetWorldCenter());
and this to move left
b2Vec2 impulse(4, 0);
body->ApplyLinearImpulse(impulse, body->GetWorldCenter());
This works, but when I press right and then left, the player doesn’t immediatly go left, but continues right for a while, and then goes left. How do I make sure this doesn’t happen?
set the body’s linearVelocity to b2Vec2_zero before applying the new force – LearnCocos2D yesterday