I am using cocos2dx and setup two Sprites with same Physics Body definitions see below
PhysicsBody *physicsBody=PhysicsBody::createBox(size,PhysicsMaterial(1.0f,0.0,0.5f),Vec2(0, size.height*0.5));
physicsBody->setGravityEnable(true);
physicsBody->setCategoryBitmask(1);
physicsBody->setCollisionBitmask(1);
physicsBody->setContactTestBitmask(true);
physicsBody->setDynamic(true);
physicsBody->setContactTestBitmask(0xFFFFFFFF);
physicsBody->setMass(5.0f);
node->setPhysicsBody(physicsBody);
I am defining a collision detection
between both the physics bodies
auto contactListener=EventListenerPhysicsContactWithBodies::create(player1->getPhysicsBody(), player2->getPhysicsBody());
contactListener->onContactBegin = CC_CALLBACK_1(Game::onPlayerContact, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);
I don't want these two bodies to collide with each other or, any effect of physics if they collide. I am doing
bool Game::onPlayerContact(cocos2d::PhysicsContact &contact){
auto nodeA = contact.getShapeA()->getBody()->getNode();
auto nodeB = contact.getShapeB()->getBody()->getNode();
if(nodeA != NULL && nodeB != NULL){
printf("\nPlayers collided");
}
return false;
}
I am not able to bypass the contact between two bodies, what else should be done to avoid collision?
Please Help.
Thanks.