ApplyImpulse doesn't work when using Physics Integrated

Hello guys,

I’m using cocos2d-x version 3.3 and I’m using the integrated physics on it.
I init a DrawNode and set physicsBody on it then use ApplyImpulse but it doesn’t work.
Here is my code snippet:

// Physics World init
this->physicsWorld->setGravity(0, -300);

// Create ball    
auto ball = DrawNode::create();
ball->drawDot(Vec2(0, 0), 15, Color4F(1, 1, 1, 1));
ball->setPhysicsBody(PhysicsBody::createCircle(15, PHYSICSBODY_MATERIAL_DEFAULT, Vec2(0.5, 0.5)));
ball->getPhysicsBody()->setDynamic(true);
ball->getPhysicsBody()->applyImpulse(Vec2(100, 1000));

The ball keeps falling even I called applyImpulse.
Please help me to solve this. Thank you very much! :smile:

P/S: I’m using cocos2d-x v3.3 and deploy project on mac os 10.9 to iOS 7 device.

Hi…
Code seems to be fine to me… I though never tried it using DrawNode but I’ve played around a lot with sprites and physics bodies with integrated physics engine.

Can you try few things… to check exactly where is the problem…

Replace the 2 lines

by simply
auto ball = Sprite::create(“someSmallBall.png”); // Give it some sprite…
// You may change 15 in your statements to the ball->getContentSize.width()/2

and check whether this works…
if this also doesnot works then problem is something else…

Hi catch_up,
Thanks for answer my question :smile:
After compare with some other code, I realize that the function applyImpulse can work. But the problem is I used Material Default for my object, so it seems like not move… When I tried to change material values, it worked perfectly! :smile:

Thanks for showing me a way! :smile:

Did u change the density?
Earlier I was trying to suggest you to give some mass to the body then I thought first lets check whether even simple thing is working or not :smiley:
Good that it worked

Thanks @catch_up :smile:

I found the link here: https://www.youtube.com/watch?v=nxXyFdQLF1c

And I used these values for my physics material and it worked :smile:
This is my values:
Density: 0
Restitution: 1
Friction: 0

I think this link is very useful for newbie (like me lol) :smile: it helps me a lot :smiley: