I set the gravity scale property of a Box2d body. I would like to change the gravity scale when the body reaches a specific position. Can this be done? If yes, how can it be achieved.
1
votes
2 Answers
0
votes
In my case I set constant speed for falling objects like this.
#define MIN_SPEED 2.0f
-(void)update:(ccTime) dt
{
b2Vec2 vel = self.body->GetLinearVelocity();
if( ABS(vel.x) > MIN_SPEED )
{
if(vel.x>0)
vel.x = MIN_SPEED;
else
vel.x = -(MIN_SPEED);
}
if( ABS(vel.y) > MIN_SPEED )
{
if(vel.y>0)
vel.y = MIN_SPEED;
else
vel.y = -(MIN_SPEED);
}
self.body->SetLinearVelocity(vel);
}