Physics Body bug with gravity. Sprite shooting into sky

Physics Body bug with gravity. Sprite shooting into sky
0.0 0


I’m experiencing an issue that I’ve been having since version 3.8. The problem is with physics bodies and gravity. Way back when, i decided to use gravity in my game. I created a static physics body (ground), and a dynamic player sprite. When the player sprite was on top of the ground, it would jump up and down and eventually shoot into the sky. I could never get the problem solved, so i gave up, and when I came back a month later, it wasn’t happening anymore. I updated Cocos2d-x to version 3.10 and it was working normally for the last few days, gravity and all. My laptop restarted and i came back into my project, built it, and it was happening again worse than ever. The player sprite would land on the static ground because of gravity and then shoot up into the sky. I know it isn’t a problem with my code because it worked for a few days. When i observed the bouncing the sprite did while on top of the static physics body, it would go slightly into the the static body and bounce right back out. I figured that the gravity was causing the sprites body to go slightly inside the static body and then the static body was shooting it right back out. If this is not a bug, how would i go about fixing it? else if it is a bug, you have been notified


What is physic engine that you use ? Box2d or Chipmunk ?


It sounds to me like there’s a variable somewhere that is not initialised - just a guess here, but have you set the restitution to 0?

If you have defined but not initialised restitution, then maybe when it’s working it’s just fortunate that it is initialised to a low number.

I think restitution of 0 means no bounce, 1 means perfect bounce - so an uninitialised value outside this range could be giving you your issue?

The only other thing I can think of would be tunnelling - your player travels so fast that it partly tunnels into the ground - and the physics engine compensates by throwing it up out of the ground.

It should only tunnel at high speed - so does this still happen if your player drops from a small height?

It may also be (thinking as I type, here) that you have many joints in your body - this can cause issues similar to how you describe if a ‘pointy’ physics object in your sprite hits a joint in your ground body.

This can be tested by making both the ground and your sprite a simple rectangle - I remember there being a post on this on - but that site is blocked at work so I can’t find it for you right now.


I have the restitution for both the ground and rectangular bodied sprite set to 0.2, the sprite when on the static body (from not moving at all) will start bouncing and dipping into the ground and then shoot up into the sky after about 10 seconds. The sprite starts slightly above the ground so as to not make it shoot out from started inside the ground and gravity is set to default. I’ve tried all different restitutions and it happens no matter what


The integrated physics engine


yeah, now i meet that trouble. Did you fix this?