Chipmunk Auto Jump

Chipmunk Auto Jump
0.0 0

#1

Hey!

I need quick help!
I am trying to make a platform game. I started with the physics part. The problem is that, even with no input, my body jumps automatically. I don’t understand why. Can anyone please explain?

My Player’s Body:

mPhysicsBody = PhysicsBody::createBox(getContentSize(), PhysicsMaterial(0.1, 0.0, 0.5));
mPhysicsBody->setDynamic(true);
mPhysicsBody->setMass(120);
mPhysicsBody->setRotationEnable(false);

My Ground:

mGroundSprite = Sprite::create();
mGroundSprite->setAnchorPoint(Vec2(0, 0));
mGroundSprite->setPosition(0, 0);
mGroundSprite->setContentSize(Size(size.width, -50));
mGroundBody = PhysicsBody::createBox(Size(size.width, -50), PhysicsMaterial(1, 0.0, 0.5));
mGroundBody->setDynamic(false);

My Physics World:

scene->getPhysicsWorld()->setGravity(Vec2(0, -350));


#2

Anyone knows the reason?


#3

I had a similar problem. It seemed to be a result of the physics simulation updating faster than the game.
I solved it by manually stepping the physics forwards.


#4

Do I do it like this?

scene->getPhysicsWorld()->setAutoStep(false);
scene->getPhysicsWorld()->setSpeed(2.0);

#5

Like this:

scene->getPhysicsWorld()->setAutoStep(false);

And then in an update function:

auto scene = Director::getInstance()->getRunningScene() ;
scene->getPhysicsWorld()->step(dt);