i have a box how do collision with sides left and right sprite give (game over)
and on the top no
i have this code
sorry my english
bool PlayScene::onCollisionBegin(PhysicsContact &contact){
auto shapeA = contact.getShapeA();
auto nodeA = shapeA->getBody()->getNode();
auto shapeB = contact.getShapeB();
auto nodeB = shapeB->getBody()->getNode();
if ((nodeA->getTag() == TagOfSprite::ROCK_SPRITE && nodeB->getTag() == TagOfSprite::RUNNER_SPRITE)
|| (nodeB->getTag() == TagOfSprite::ROCK_SPRITE && nodeA->getTag() == TagOfSprite::RUNNER_SPRITE))
{
log("==game over");
}
return true;
}
where find tutorials on how use chipmunk in cocos2d-x 3.x and examples in cocos2d-x 3.x
Your code seems alright, what exactly is the problem?
Check out the Programmer’s Guide and the cpp-tests
@SonarSystems has good video tutorials on pretty much everything cocos2d-x.
I guess your collision filters are not properly set.
Have you at least debugged it and see if the code reach the OnCollisionBegin code?
I think there are chipmunk samples in the cpp_tests
how to do this, collision in chipmunk…
please code in c++
I’m not sure how it will work but I guess you’ll have to check the angle of the collision normal?
I’ve not worked with physics so I can’t say. Maybe someone more experienced with physics can help out.
I looked up the API and I guess it will be something like this -
auto normal = contact.getContactData()->normal;
This will give you a vec2.
Then you can use -
auto angle = normal->getAngle();
Which will give you the angle (in radians) with respect to the X axis as a float.
You can then check the angle to see if it hit from the side or from the top.
I hope that helps 