How to pass each other By PhysicsWorld

please tell me.
In the code I wrote, the ball hits in the middle and stops.
I want to make rolling balls pass each other.
Thanks.

Bad

auto blueBall = Sprite::create(“s.png”);
blueBall->setPosition(Vec2((visibleSize.width/2 + origin.x) -200, (visibleSize.height/2 + origin.y) +300));
auto blueBallBody = PhysicsBody::createCircle((blueBall->getContentSize().width / 2), PhysicsMaterial(1.0f, 0.0f, 0.5f));
blueBallBody->setDynamic(true);
blueBallBody->setRotationEnable(true);
blueBall->setPhysicsBody(blueBallBody);
addChild(blueBall, 2);

auto redBall = Sprite::create("ss.png");
redBall->setPosition(Vec2((visibleSize.width/2 + origin.x) +200, (visibleSize.height/2 + origin.y) +300));
auto redBallBody = PhysicsBody::createCircle((redBall->getContentSize().width / 2), PhysicsMaterial(1.0f, 0.0f, 0.5f));
redBallBody->setDynamic(true);
redBallBody->setRotationEnable(true);
redBall->setPhysicsBody(redBallBody);
addChild(redBall, 3);

auto InclinationLeft = Sprite::create("sss.png");
InclinationLeft->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
InclinationLeft->setPosition(Vec2((visibleSize.width/2 + origin.x) +0 *deviceScale, (visibleSize.height/2 + origin.y) -550 *deviceScale));
InclinationLeft->setScale(deviceScale);
auto InclinationLeftBody = PhysicsBody::createBox(InclinationLeft->getContentSize(), PhysicsMaterial(1.0f, 0.0f, 1.0f));
InclinationLeftBody->setDynamic(false);
InclinationLeft->setPhysicsBody(InclinationLeftBody);
InclinationLeft->setRotation(20);
this->addChild(InclinationLeft, 1);

auto InclinationRight = Sprite::create("sss.png");
InclinationRight->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
InclinationRight->setPosition(Vec2((visibleSize.width/2 + origin.x) +0 *deviceScale, (visibleSize.height/2 + origin.y) -550 *deviceScale));
InclinationRight->setScale(deviceScale);
auto InclinationRightBody = PhysicsBody::createBox(InclinationRight->getContentSize(), PhysicsMaterial(1.0f, 0.0f, 1.0f));
InclinationRightBody->setDynamic(false);
InclinationRight->setPhysicsBody(InclinationRightBody);
InclinationRight->setRotation(-20);
this->addChild(InclinationRight, 1);

Please read this thread…

1 Like

Thank you. I did it😊

@smitpatel88 You are correct as always, my friend. I was going to reply check bitmasks until I saw your reply :slight_smile:

Thanks :smile: .