I've created a platform that goes up and down in my game and in one of the scheduled methods I have it applying a force +/- depending on whether or not it is above or below the top and bottom floors. However it's not working out quite right.
any suggestions on other ways to implement this?
//////// MOVING PLATFORMS
std::vector<b2Fixture *>::iterator p2;
for(p2 = v_plaftorm_fixtures.begin(); p2 != v_plaftorm_fixtures.end(); ++p2) {
b2Fixture *b = *p2;
b2Body *pBody = b->GetBody();
CCSprite *psprite = (CCSprite *)pBody->GetUserData();
int tag = [psprite tag];
if (tag == TAG_MOVING_PLATFORM_Y1)
{
int posy = pBody->GetPosition().y * PTM_RATIO;
if (posy > 2000) {
pBody->ApplyForce(b2Vec2(0,-100),
pBody->GetWorldCenter());
}
else
if (posy < 100) {
pBody->ApplyForce(b2Vec2(0, 10000),pBody->GetWorldCenter());
}
}
}