I have issue regarding speed in air.
When I jump and move simultaneously that time speed of player increase. I use impuls for jump and I use force for movement .I want to know how to slow down it when player is in air.
This is my code of movement left and right
-(void)update:(ccTime)dt :(b2Body *)ballBody :(CCSprite *)player1 :(b2World *)world
{
if (moveRight.active==YES)
{
// maxSpeed=10.0f;
ballBody->SetActive(true);
// b2Vec2 locationworld=b2Vec2(maxSpeed,0);
double mass=ballBody->GetMass();
ballBody->ApplyForce(mass*locationworld, ballBody->GetWorldCenter());
ballBody->SetLinearDamping(1.2f);
}
else if(moveLeft.active==YES)
{
ballBody->SetActive(true);
b2Vec2 locationworld=b2Vec2(-10,0);
double mass=ballBody->GetMass();
ballBody->ApplyForce(mass*locationworld, ballBody->GetWorldCenter());
// ballBody->SetLinearDamping(1.2f);
}
}
And following is for jumping player
-(void)jump:(b2Body*)ballBody:(ccTime)dt:(BOOL)touch
{
if (touch)
{
if (jumpSprte.active==YES)
{
ballBody->SetActive(true);
b2Vec2 locationWorld;
locationWorld=b2Vec2(0,25);
ballBody->ApplyLinearImpulse(locationWorld, ballBody->GetWorldCenter());
}
}
}
So where i used logic??
Thanks in advance
You need to model air resistance to slow the player down in the air. There are several ways to do this depending on how realistic you want the simulation to be. For a simple model
linearDampeningwould slow it down.True air resistance is not linear. To model this in a more realistic way you’d need to use something like this:
Fis the total force of the air dragCis a drag constant that depends on the shape of the objectvis the velocity vector (|v|is the magnitude of the velocity, or length if you so wish)It also sounds like your players are able to increase their speed while in the air using move. This is because you allow the player to apply force while his legs aren’t touching the ground. In order to disallow this if this is your goal make sure that when the character is touching the ground is the only time when more force can be applied to make him move.
Note that this all very much depends on what sort of game you want this to be. If it looks and feels good when making physics for games it is good. Do not stress out if you don’t manage to make a wholly accurate simulation of reality as long as the end result plays well.