i am guessing your ground is Static and player body is Dynamic, so if thats the case then you have to forcefully set collision restitution to 0. In your .h file define it like
// Physics Contact Listener.....
bool onContactBegin(PhysicsContact& contact);
bool onContactPreSolve(PhysicsContact& contact,
PhysicsContactPreSolve& solve);
void onContactPostSolve(PhysicsContact& contact,
const PhysicsContactPostSolve& solve);
void onContactSeperate(PhysicsContact& contact);
and in you init() method define it like
//*************** Setting our Physics Body Contact Listener…**********
EventListenerPhysicsContact *contactListener =
EventListenerPhysicsContact::create();
contactListener->onContactBegin =
CC_CALLBACK_1(StateMachine::onContactBegin, this);
contactListener->onContactPreSolve =
CC_CALLBACK_2(StateMachine::onContactPreSolve, this);
contactListener->onContactPostSolve =
CC_CALLBACK_2(StateMachine::onContactPostSolve,this);
contactListener->onContactSeperate =
CC_CALLBACK_1(StateMachine::onContactSeperate,this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener,
this);
now we to avoid jumping effect when two bodies collide we will only need our “preSolve” callback, this is a mediator callback and is called just before calculating final collision values for two bodies.
define it like this.
// Calling it to eliminate The Jumping Effect... Restitution
bool StateMachine::onContactPreSolve(PhysicsContact& contact,
PhysicsContactPreSolve& solve) {
solve.setRestitution(0);
return true;
}
now this should do the trick for you, hope it helps
EDIT:-
i am Assuming that you are using cocos2d-x internal physics (chipmunk), if not then there might be some syntactical dissimilarities although conceptual working is same.
keep in mind that this will work for every collision that will happen, if you want to filter that out and manually handle which two bodies will not bounce after collision then in that case you can filter it out like
PhysicsBody* a = contact.getShapeA()->getBody();
PhysicsBody* b = contact.getShapeA()->getBody();
// only do this when player collide with world, for other collisions
// it will work like normal
if (a->getTag() == Player::_playerBodyTag || b->getTag() ==
Player::_playerBodyTag){
solve.setRestitution(0);
}