Anyone seen this before?
I implemented a b2ContactListener to determine when the player is on a platform or not. Any new (added) contact with the platform is stored in an array and removed when it ends.
My assumption was that if the contact array length was > 0, the user was on a platform. When the array reaches zero, the user has jumped or fallen off a platform.
However when the player walks on a slightly curved platform and across an edge, the b2ContactListener will end the prior edge's contact before adding a new one. This leaves a short but significant period (~.1 seconds) where the player is on the platform but my contact array length is zero.
Hope that makes sense and that someone has an alternative solution. My platform testing is a fairly common scenario so I'm assuming that my approach is somehow flawed.
Thanks,
Anthony
I implemented a b2ContactListener to determine when the player is on a platform or not. Any new (added) contact with the platform is stored in an array and removed when it ends.
Code:
contact->GetWorldManifold( &WorldManifold );
const b2Vec2& normal = WorldManifold.m_normal;
float angle = atan2(normal.x,normal.y);
angle = RadiansToDegrees(angle);
if (angle > -60 && angle < 60) {
contacts[contactCount] = contact;
contactCount++;
isOnPlatform = TRUE;
}
const b2Vec2& normal = WorldManifold.m_normal;
float angle = atan2(normal.x,normal.y);
angle = RadiansToDegrees(angle);
if (angle > -60 && angle < 60) {
contacts[contactCount] = contact;
contactCount++;
isOnPlatform = TRUE;
}
My assumption was that if the contact array length was > 0, the user was on a platform. When the array reaches zero, the user has jumped or fallen off a platform.
However when the player walks on a slightly curved platform and across an edge, the b2ContactListener will end the prior edge's contact before adding a new one. This leaves a short but significant period (~.1 seconds) where the player is on the platform but my contact array length is zero.
Hope that makes sense and that someone has an alternative solution. My platform testing is a fairly common scenario so I'm assuming that my approach is somehow flawed.
Thanks,
Anthony