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

In my game the character can fall in two directions. The user clicks right or left button to "push" the character to balance them, so they don't fall. I'm not sure how to increase the forces applied to the character for each press.

function left:touch(e)
    if(e.phase == "began") then
        boy:applyLinearImpulse(-0.5, .5, boy.x, boy.y)
    end
end

function right:touch(e)
    if(e.phase == "began") then
        print("right"); 
        boy:applyLinearImpulse(2.1, .5, boy.x, boy.y)
   end
end
left:addEventListener("touch", left );
right:addEventListener("touch" , right );
share|improve this question
up vote 1 down vote accepted

It looks like you need another variable to indicate velocity in each direction. It would look something like this:

function left:touch(e)
    if(e.phase == "began") then
        boy.velX = boy.velX - 0.5
        boy:applyLinearImpulse(boy.velX, boy.velY, boy.x, boy.y)
    end
end
share|improve this answer
    
Thank u very much... – divya Mar 13 '12 at 14:12

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.