Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

enter image description here

Hello Friends. This is my demo game screen-shoot. Here i am using three buttons. Right-bottom button is used for jump and left-bottom buttons used for move left and right.

I have some questions 1) should i use linearImpuls for jump body?? 2) For move right and left which types of force i applied???

PLease tell me i am confusing to use linearImpuls, applyforce and linearVelocity.

Thanks in advance

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

To jump you should use linear impulse upwards. To run you have a couple of options. You could apply a force which wil over time increase velocity. You would then need to limit the maximum velocity. This is done by applying damping. You also want the player to come to a complete stop when not pressing left or right. This is done by applying friction. Set friction and damping quite high to make the controls feel responsive.

You could also instead make a velocity check to see if you are moving to the right or left and apply an impulse if not. This will lead to a bit more jerky behaviour though (which might on the other hand be what you want)

share|improve this answer
    
Thanks mikael i am using linearImpuls fr jumping and force for movement left-right and for stoping friction used. But i have one problem in jumping when i press jump button once it jumps at that time i press jump button 2nd time it jump continuos but i don't want to do that. I want when player touch floor or wall or point that time jump will perform. How can i do this?? Sorry for poor english –  Diken Sep 3 '12 at 5:16
    
I have another issue regarding your answer.How to limit the maximum velocity?? How can i use damping for limit jump?? –  Diken Sep 3 '12 at 5:44
    
Sorry but issue of jump is solved.But another issue is when player jump using impuls and movement is done using force so when player jump at simultaneously movement perform that time movement of player is gone high. what to do to resolve this speed?? –  Diken Sep 3 '12 at 6:38
    
please help me... –  Diken Sep 3 '12 at 10:01
    
Your maximum velocity will be determined by the linear damping. Pretty much like if you are riding a bike, if you exert your maximum force you still won't go faster than a certain speed. I don't really understand you last question, could you clarify? –  Mikael Högström Sep 3 '12 at 10:37
show 5 more comments

How can i set maximum speed?? Because i am set one force when i press move button

if (moveRight.active==YES) 
    {   
            ballBody->SetActive(true);
        b2Vec2 locationworld=b2Vec2(10,0);
            //b2Vec2 force=b2Vec2(1.0,0);
        double mass=ballBody->GetMass();

        ballBody->ApplyForce(mass*locationworld, ballBody->GetWorldCenter());
  //      ballBody->SetLinearDamping(1.2f);

        NSLog(@"Speed Of Velocity Right: %f",ballBody->GetLinearVelocity().x);
    }

This condition is in update method. So where i set maximum speed??

share|improve this answer
    
This should maybe either be a part of your question (using edit) or another question altogether. Anyway, I haven't used cocos2D but you should be able to check the length of the linear velocity vector and if it is faster (longer) than max speed then set the vector to have length of maxspeed. Or, if it is only x-speed you wish to limit then set it to maxspeed instead. –  Mikael Högström Sep 3 '12 at 13:15
    
But sir how can i set maxspeed?? –  Diken Sep 5 '12 at 5:45
    
Try: if (ballBody.Velocity.X > MAX_SPEED ) ballBody.Velocity.X = MAX_SPEED; if (ballBody.Velocity.X < -MAX_SPEED ) ballBody.Velocity.X = -MAX_SPEED; –  Mikael Högström Sep 6 '12 at 12:38
add comment

Your Answer

 
discard

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.