Hey guys,
I'm using Chipmunk.
I've got platforms in my game that descend slowly over time at a variable rate. I've implemented the platforms as line segment shapes. Each platform has a body and a line segment shape. The body has infinite mass and infinite moment of inertia. The elasticity of the shape is 0.0f.
The character is a body with 1.0f mass, and infinite moment of inertia (I don't want him to rotate). He has a square poly physics shape with 0.0f elasticity. His body is added to the physics space so that he is affected by gravity.
I do not add the body of the platforms to the physics space because I don't want them to fall with gravity. Instead I have a scheduled update loop and I slowly move the position of the body down the screen at a variable rate.
The problem I'm having is that as the character falls from gravity and lands on a descending platform he will continually "bounce" off the platform. I.e. the platform descends automatically, then it's like gravity kicks in again and the character catches up and falls back onto the platform. The character does not seem to stay riding on the platform no matter how high I crank gravity. Increasing gravity just increases the frequency of the "bounces", i.e. short little bounces vs. longer drop / slower bounces.
I've tried changing the order in which I do the updating of the platform positions and the stepping of the physics space but neither before or after seems to change the behaviour.
Can anyone offer me any advice on how I can try to get my character to ride the platform better?
Here's what my physics and platform update looks like:
// Update the level object manager. This is where the platforms are dropped
// at a variable rate.
[[LevelObjectManager sharedInstance] update:dt];
// Step physics. We do this at a fixed timestep.
// Also we cap it at 0.25f delta time in case the game was paused or something.
if (dt < 0.25f)
{
physicsTimeAccumulator += dt;
}
else
{
physicsTimeAccumulator += 0.25f;
}
while (physicsTimeAccumulator >= dt)
{
// Step the physics space.
isCharacterFlying = YES;
cpSpaceStep(space, PHYSICS_UPDATE_FRAMERATE);
physicsTimeAccumulator -= PHYSICS_UPDATE_FRAMERATE;
}