1
\$\begingroup\$

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 );
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .