How to setup a smooth character jump with physics?

Hello guys,

I am working on an endless runner where i need my hero to jump from rock to rock (rock changes in length randomly. I am using physics for collisions (hero to rocks and hero to flying obstacles) I am trying to figure the best way to implement a jump  I am not too worry about the logic of the single/double jump. I am mostly having hard with the jump itself. I have a look at many endless runner games and most of them have a nice and smooth jumps. I tried just using applyLinearImpulse inside a  touch event (so every time the player touch the screen, the hero gets a upward force and then with a timer later on gets an downward force. That seems to be a little too jumpy.

I also try the same impulse method but within a enterFrame. I detect a screen touch and I set variable (touchFlag) to true or false. The enterFrame then apply a force either upward or downward. It is much smoother but I do not want the player to simply keep his/her finger on the screen and stay in the air the all time!

I was wondering if someone could suggest a better to approach this problem. To help visualize what I am looking for, maybe you can check the following two apps:

I  like how smooth the hero’s jump:

https://itunes.apple.com/us/app/alien-life-race-anti-gravity/id606601428?mt=8

I like the double jumps in this game:

https://itunes.apple.com/us/app/disco-style-runner-free-saturday/id581348057?mt=8

THANK YOU!

Mo

ps: I am also not sure how density affect the movement. I also assuming that setting the hero bounce to zero means the hero will not bounce when hitting the rocks down below (or in the top of the screen)?

If you have gravity set, then you don’t need to apply the second downward force, just apply a linear impulse upwards and gravity takes care of the rest. I’m in the middle of producing an endless runner and have my gravity set at 15, that gives a nice smooth jump arc.

Hello Andy. Sorry for the delay. Unfortunately I do not use gravity in my game (many moving objects which will not work if there is gravity involved) I think I making progress. I will share when I happy with the result! Thanks again for taking the time Andy. Mo.

I would suggest using gravity and set object.gravityScale=0 for all objects that shouldn’t be effected by it.

WOW! I learn something new everyday! I did not know about gravity scale. I will try that.

THANK YOU!

Mo

If you have gravity set, then you don’t need to apply the second downward force, just apply a linear impulse upwards and gravity takes care of the rest. I’m in the middle of producing an endless runner and have my gravity set at 15, that gives a nice smooth jump arc.

Hello Andy. Sorry for the delay. Unfortunately I do not use gravity in my game (many moving objects which will not work if there is gravity involved) I think I making progress. I will share when I happy with the result! Thanks again for taking the time Andy. Mo.

I would suggest using gravity and set object.gravityScale=0 for all objects that shouldn’t be effected by it.

WOW! I learn something new everyday! I did not know about gravity scale. I will try that.

THANK YOU!

Mo