Hi, here are some code.
class Missile
{
....
cocos2d::Sprite sprite{ nullptr };
cocos2d::PhysicsBody physicsBody{ nullptr };
float damage{ 0.0f };
....
}
....
class Zombie
{
....
cocos2d::Sprite sprite{ nullptr };
cocos2d::PhysicsBody physicsBody{ nullptr };
float hp{ 0.0f };
....
}
What I want to do is adding Physics Contact Event after initializing sprite and physics so
when the missile hits zombie, zombie will decrease hp by missile’s damage.
contactListener->onContactBegin = [this](cocos2d::PhysicsContact& contact)->bool
{
auto A{ contact.getShapeA()->getCategoryBitmask() };
auto B{ contact.getShapeB()->getCategoryBitmask() };
if (A != B)
{
// Find which missile has hit.
// Find which zombied has hit
if(A == ObjectTypeBitmask::Missile)
{
}
else
{
}
return true;
}
return false;
}
When the missile hits zomibe, it calls event function above. But I could find which ones have contacted.
How do I find which missile and zombie have contacted?