Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have issue regarding speed in air. When i jump and move simultaneously that time speed of player increase.For jump i am using impuls and for movement i am using force.I want to slow speed when player is in air.

Thanks in advance

Following is my update method ih HUDLayer

-(void)update:(ccTime)dt :(b2Body *)ballBody :(CCSprite *)player1 :(b2World *)world

    if ( 
        b2Vec2 locationworld=b2Vec2(maxSpeed,0);
        double mass=ballBody->GetMass();
        ballBody->ApplyForce(mass*locationworld, ballBody->GetWorldCenter());
      //  ballBody->SetLinearDamping(1.2f);
    else if(
        b2Vec2 locationworld=b2Vec2(-10,0);
        double mass=ballBody->GetMass();
        ballBody->ApplyForce(mass*locationworld, ballBody->GetWorldCenter());
    //    ballBody->SetLinearDamping(1.2f);


} Following is jump

    if (touch) 

        if ( 
            b2Vec2 locationWorld;
//        double mass=ballBody->GetMass();
            ballBody->ApplyLinearImpulse(locationWorld, ballBody->GetWorldCenter());
      //  ballBody->ApplyForce(mass*locationWorld, ballBody->GetWorldCenter());


So where i apply logic??

share|improve this question Perhaps this can help? – Sidar Sep 5 '12 at 6:37
Inertia makes it harder to change velocity. It will not slow the player down which I believe is what the OP is asking for. – ClassicThunder Sep 5 '12 at 6:56
Yes i am trying ballBody->SetLinearDamping(1.2f); but can not see any effect. – Diken Sep 5 '12 at 7:06
Well that is a ridiculously huge value for linear damping. "Normally you will use a damping value between 0 and 0.1." You should keep this handy – ClassicThunder Sep 5 '12 at 7:14
up vote 4 down vote accepted

Sounds like you want a friction joint. Set the two anchor points to zero so the friction doesn't have any direction. Below is vague pseudocode of how to create a friction joint and add it to your world.

Also make sure you keep the Box2D Manual handy.

var frictionJoint = new FrictionJoint();

frictionJoint.localAnchorA = new Vector2(0,0);
frictionJoint.localAnchorB = new Vector2(0,0);

frictionJoint.bodyA = yourBall;
frictionJoint.bodyB = ASquareAsLargeAsTheAreaYouNeedFrictionIn

frictionJoint.maxForce = 0.5; //This the most force the joint will apply to your object. The faster its moving the more force applied
frictionJoint.maxTorque = 5; //Set to 0 to prevent rotation

share|improve this answer
How to add friction joint and which anchor point i have to set to zero?? – Diken Sep 5 '12 at 7:05
@Diken updated answer – ClassicThunder Sep 5 '12 at 7:12
This code is apply in update method of I show you my code of jump and movement of player – Diken Sep 5 '12 at 7:16
No just once after you create the two necessary bodies. – ClassicThunder Sep 5 '12 at 7:20
But player is a dynamic body and which is define in your code as yourBall but what about bodyB?? – Diken Sep 5 '12 at 7:25

Unlike surface friction between solids, air friction (drag) depends on the speed of the object, squared.

An easy way to model friction and drag

F(friction) = -k;
F(drag) = speed * speed * -k;

Both forces act in the opposite direction to the velocity of the object.

Notice that surface friction is a constant whereas air friction (drag) must be modified each frame according to the object speed (length of velocity vector)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.