The Longer You Touch, The Higher He Jumps?
FreiGames
Member Posts: 158
So as the title says I'm having a hard time making my character jump higher the longer I touch!
Any suggestions what to do?
Thanks, cheers!
Any suggestions what to do?
Thanks, cheers!
Comments
Try it out and hopefully you are done with that! Let me know if it doesn't work out.
Hope that helps,
Slamuel
when player touch screen, add to the pos Y of the player the max possible height of the jump (i.e, 90) and store the value in a self.attribute. Then, change velocity Y to a value that determine the speed of the jump and take away accelerate down/gravity (so accelerate down only if player isn't jumping). Then, if player.y gets higher than that self attribute we stored earlier, put gravity/acceleration back. Also, put gravity/acceleration back if player lift the finger. And that's pretty much it
Someone got template?
But if you don't want or can't pay any money, I'll try and explain an easier version of it. It's not as optimized, but it should be easier to understand.
You've got gravity/or acceleration down set.
Rule:if player touch screen and an attribute playerCanJump is true (meaning, he is on solid ground and can jump, so you should have another rule that check if he is on ground)
change a self attribute to position y of the player + max height of the jump (i.e, if the player is at posY 100, and max height is 90, result will be 190. If the player reach 190, jump will be disabled)
constrain attribute motion linear Y of the player to 300 (this value determine the min height of the jump, and also the speed of the jump itself, we use constrain because we don't take out acceleration before, like I explained in the other post. That's why this is easier but not that performant).
Now like this the player will jump, but never going down.
So we add a rule.
If player left finger from touch OR player.position.Y is equale or greater than self.attribute which we stored that 190 earlier then
attribute.canJump = false.
Setting it back to false will stop the constrain, so the acceleration or gravity will kick back in and get him back to the ground.
Cheers!
It worked, thank you SO much, if there is ever anything I can do for you let me know!