-
chickenLikes 0Problem Description
Hi
I’m trying to get my sprite to jump on touch from a non-dynamic surface. It goes up fine, but on collision from a ‘grass’ sprite, it travels through. The collision is detected, as you can see from the CCLOG in the xcode window on the bottom left of the screencast. A video is here:
My code for the grass sprite is here:
//grass
auto grassSprite = Sprite::create("grass.png");
PhysicsMaterial material(1.0f,1.0f,0.0f);
//auto grassBody = PhysicsBody::createBox(grassSprite->getContentSize(), material);
auto grassBody = PhysicsBody::createBox(grassSprite->getContentSize());
grassBody->setDynamic(false);
grassBody->setCollisionBitmask(1);
grassBody->setContactTestBitmask(1);
grassSprite->setPhysicsBody(grassBody);
and my code for the sprite is here:
PhysicsMaterial mat(0.0f,1.0f,0.0f);
auto playerBody = cocos2d::PhysicsBody::createCircle(_player->getContentSize().width/2, mat);
playerBody->setCollisionBitmask(2);
playerBody->setContactTestBitmask(1);
playerBody->setDynamic(true);
_player->setPhysicsBody(playerBody);
_layer->addChild(_player,100);
Any idea what’s going on?
Many thanks in advance
Birju
-
Sonar Systems adminLikes 0
For something as basic as this use your own bounding box collision detection.
-
chickenLikes 0
Thanks, I’ve been messing around with this for a while now and you’re right so I am considering moving stuff around manually instead of relying on physics. Pretty much all sprites are ‘spongey’ when there is a collision. Any idea why this is? How can we prevent it? I’m using 3.10
Thanks for your help
Birju
-
Sonar Systems adminLikes 0
How fast are your objects moving?
-
chickenLikes 0
Hi thanks for the response.
They’re not moving that fast really:
auto jumpAction = cocos2d::JumpBy::create(1, Vec2::ZERO, visibleSize.height/4, 1);
What is interesting is that when I drop the ball from the middle of the screen, it bounces fine (only a tiny overlap) but when I Jump it’s pretty bad, it does crazy stuff, I’ve uploaded a new video here:
Any help would be appreciated.
Many thanks
Birju
-
Sonar Systems adminLikes 0
Have you tested it on a device?
-
chickenLikes 0
yeah, figured it out – the jump action keeps a residual velocity. I instead did a MoveBy up and let it drop naturally using gravity. much better now.
Thanks for the help
Birju
-
Sonar Systems adminLikes 0
Great to hear you have solved the problem.
If you have anymore questions don’t hesitate to ask.
Login to reply