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.

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)
end

please help me how to code.

share|improve this question
2  
Flagged as not a real question. Please try to tell us what you want to do http://translate.google.com/ –  Byte56 Mar 13 '12 at 15:28
add comment

1 Answer 1

Try this:

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

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
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.