Hello everyone, this is my first post here so i apologize for everything stupid i might say. I've searched everywhere but i couldn't find answers, so here it is:
I am writing a physics based 2d platform for a college exam, and for now I am simply handling the character's jump with this line of code (yup its name's Steve):
game.steve:applyLinearImpulse(0, game.steve.jumpForce, game.steve.x, game.steve.y)
..which is inside a simple touch event handler function, called by a button pressed on the screen.
Everything works fine (he jumps only when i want to, i've already implemented the "enabling" rules for the jump), but there's one problem: no matter how long the touch event lasts, he will always jump with the same force and reach the same height.
I would like to implement some sort of interpolation between a minimum value of force of the character's jump to a maximum, which will depend on how long the button is pressed; in fact this logic is very similar to other games like Mario, where the jump can be regulated in height depending on the duration of the input.
[Forgot to say that jumpForce must be a negative value to push the character up in the air.]
The aim is to have the acceleration to be higher at the start of the touch and decrease over time, to a certain point in which force is 0 and the character will start falling; also, it should be possible to stop everything on the release phase of the touch event while resetting the jumpForce to its maximum value.
The function should be something like this:
I have tried with easing functions in the transition.to, but unfortunately they don't work with just numbers. I also tried with enterFrame loops, but i couldn't manage to reset properly the jumpForce.
Anybody can help me?
Thanks in advance