Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

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 i have to control handstand man using accelerometer. i used this code:

function acc:accelerometer(e)  
        if(e.yGravity > 0.1 and e.yGravity < 0.2)then
    boy:applyLinearImpulse(0.1, .5, boy.x, boy.y)

    elseif(e.yGravity > 0.2 and e.yGravity < 0.3)then
    boy:applyLinearImpulse(0.2, .5, boy.x, boy.y)

    elseif(e.yGravity > 0.3 and e.yGravity < 0.4)then
    boy:applyLinearImpulse(0.3, .5, boy.x, boy.y)

    elseif(e.yGravity > 0.4 and e.yGravity < 0.5)then
    boy:applyLinearImpulse(0.4, .5, boy.x, boy.y)

    elseif(e.yGravity > 0.5 and e.yGravity < 0.9)then
    boy:applyLinearImpulse(0.5, .5, boy.x, boy.y)

    elseif(e.yGravity > -0.1 and e.yGravity < 0.1)then
    boy:applyLinearImpulse(-0.1, .5, boy.x, boy.y)

    elseif(e.yGravity > -0.2 and e.yGravity < -0.1)then
    boy:applyLinearImpulse(-0.2, .5, boy.x, boy.y)

    elseif(e.yGravity > -0.3 and e.yGravity < -0.2)then
    boy:applyLinearImpulse(-0.3, .5, boy.x, boy.y)

    elseif(e.yGravity > -0.4 and e.yGravity < -0.3)then
    boy:applyLinearImpulse(-0.4, .5, boy.x, boy.y)

    elseif(e.yGravity > -0.5 and e.yGravity < -0.4)then
    boy:applyLinearImpulse(-0.5, .5, boy.x, boy.y)

    elseif(e.yGravity > -0.9 and e.yGravity < -0.5)then
    boy:applyLinearImpulse(-0.6, .5, boy.x, boy.y)

please help me how to code.

share|improve this question
Flagged as not a real question. Please try to tell us what you want to do – Byte56 Mar 13 '12 at 15:28

Try this:

function acc:accelerometer(e)
    boy:applyLinearImpulse(e.yGravity, .5, 0, 0)

This huge if statement looks terrible and is definitely the wrong way to be handling your problem, whatever that is. However, you don't describe your problem at all, you don't explain this code (would like to know what exactly are the parameters for applyLinearImpulse), and this website is not a place to submit chunks of code and expect others to do your work for you. If you want a helpful answer, please ask a helpful question. Good luck.

share|improve this answer
i have to increase the force based on the position.same time i have to change the picture for each position. – divya Mar 14 '12 at 5:17

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.