Search code examples
cocos2d-xgame-physicscocos2d-x-3.0chipmunkphysics-engine

How to apply different amount of impulse(force) to the PhysicsBody object (cocos2d-x)?


Given the sprite with physics body ball, I want to apply different amount of the force to it in different directions. (And thus different distance for it to fly).

In the builtin physics engine (based on chipmunk) I am only able to do something like ball->getPhysicsBody()->applyImpulse(Vec2(X, Y));. But how to change the force of that impulse, I want to be able to apply different Impulse to the object.


Solution

  • Answering my question, in cocos2d-v3 applyImpulse(..) as well as applyForce(..) takes vector that specifies direction and the norm/length of that vector can be seen as the "amount" of force applied. Simply, applyForce(Vec2(1,1)) and applyForce(Vec2(100,100)) would both apply force directed at top right corner but in latter case the "amount" of that force is more.