0

I'm developing a game where the character bounces much like the "Flappy Bird" character.

I have it working well, but I'm handing the bouncing effect with a touch event and when the user double touches really quick it basically doubles the force behind the player.

Also, take for example if the player is dropping from a higher height then the gravity seems to be too much and I have to touch many more times to bring the player back up, and I just can't seem to figure out how to make every touch consistent with the amount the character bounces.

Here is my function for the bounce effect:

function flyUp(event)
    if event.phase == "began" then
        if gameStarted == false then
            player.bodyType = "dynamic"
            instructions.alpha = 0
            tb.alpha = 1
            addColumnTimer = timer.performWithDelay(1000, addColumns, -1)
            moveColumnTimer = timer.performWithDelay(2, moveColumns, -1)
            gameStarted = true

            player:applyForce(0, -300, player.x, player.y)
        else
            player:applyForce(0, -460, player.x, player.y)
        end
    end
end

...and here is where my player is defined as a physics body:

physics.addBody(player, "static",
    { density=.106, bounce=.1, friction=1, radius = 30 })

any help would be extremely appreciated, i just want the player to always move up the same amount no matter how many taps and how much he has dropped.

Thanks

2 Answers 2

0

You're probably forgetting that force determines acceleration, not velocity. So if you have an object moving downwards at speed V (V is positive value, since downward is positive in Corona) then applyForce() applies a momentary upward force (duration: one time frame) to the object, so the object's downward velocity will decrease a little bit (decelerate as a result of the upward force), but gravity is constant so you'll have to press multiple times to get enough deceleration.

What you probably want is to directly setLinearVelocity() to a negative value, thus making it look as though the object "bounced" upwards upon touch; gravity will then give it a parabolic trajectory. Also, if the object is always given the same linear velocity, it doesn't matter how many taps occur, although each tap will counter the effect of gravity with same upwards velocity.

0

Two ideas:

  • To avoid the double-touch/double-bounce, apply a cooling off period. When the user touches, ignore additional touches for some given amount of time.
  • Strictly speaking, you are getting the same amount of bounce (or upward force) per touch. It sounds like you want a variable bounce depending on the current velocity toward the ground. This shouldn't be too hard. Try applying more upward force in player:applyForce depending on the velocity on the y axis. If the player isn't falling, a smaller amount of force is needed. If they are falling at terminal velocity, a much larger force is needed.

It sounds like you recognize that "perfect" physics are less fun in your game. That's often the case. You'll likely need to experiment until something feels right.

1
  • thanks for your answer! i figured out that if i simply change applyForce to setLinearVelocity and turn the gravity down a little then the player is consistent on his floating.
    – siegs
    May 21, 2014 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.