make the ball jump

hey every one…
I made a game in my university project of the classic nokia game Bounce, i have been able to do every thing in the game except make the ball jump…i am using applyForce to move the ball, so i was thinking to make the ball jump using the same technique…heres the code snippet

[lua]–created the ball n everything
local funtion jumpLeft(e)
if(e.phase == “began”)
ball:applyForce(0,-100,ball.x,ball.y);
end
end[/lua]

using this i am able to make the ball jump but it also jumps or apply the force even when the ball is in the air…what i want to do is that the user could not jump when the ball is in the air…until or unless the ball hits the ground, then the user should be able to jump…any idea how can i achieve that… [import]uid: 48549 topic_id: 10003 reply_id: 310003[/import]

Perhaps you could check if there is no active vertical force component left? If that would fit your concept.

See http://developer.anscamobile.com/reference/index/bodygetlinearvelocity

if vy == 0 then it cant be flying or bouncing. Same for if you want to jump when it is “almost” not bouncing anymore, just check for a small enough vy.

  • Reinier [import]uid: 53290 topic_id: 10003 reply_id: 36526[/import]

Rienier man sorry i didnt get what you are saying…

should i check to see if the vy == 0 then jump else dont…

if thats the case then please elaborate that…i havnt use this function before, so can you please help me out [import]uid: 48549 topic_id: 10003 reply_id: 36528[/import]

You say that you only want the ball to be able to jump when it is not in the air, right? If an object is moving in space, it has two force vectors, X and Y, which are the two parts that make up the total kinetic energy of the object, i.e; the total force that is moving it.

By calling the function I linked to you get the 2 force components, X & Y. If there is no Y force (or a reaaally small one… up to you to limit)the ball is not moving in the vertical axis. i.e; it is not falling or rising and thus stationary on the floor.

Makes more sense now?

[import]uid: 53290 topic_id: 10003 reply_id: 36529[/import]

yea thnx man, really helped alot…thnx [import]uid: 48549 topic_id: 10003 reply_id: 36532[/import]

You’re welcome! Hope to see a few screenshots of it here when you’re done with it :slight_smile: And get a good grade for it, of course :wink: [import]uid: 53290 topic_id: 10003 reply_id: 36534[/import]

yea sure will upload some of the shots as soon as i get the good grade…=D [import]uid: 48549 topic_id: 10003 reply_id: 36560[/import]