Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Variable Jump Height
Started by lguidaldi Apr 02 2017 12:52 PM

- - - - -
4 replies to this topic
jump height variable touch event platform physics
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

lguidaldi

[GLOBAL: userInfoPane.html]
lguidaldi
  • Observer

  • 2 posts
  • Corona SDK

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:Immagine.png

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 ;)
 

 



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

You say this is for a "college exam".  What class is this for?  i.e. Full name of class.



[TOPIC: post.html]
#3

lguidaldi

[GLOBAL: userInfoPane.html]
lguidaldi
  • Observer

  • 2 posts
  • Corona SDK

You say this is for a "college exam".  What class is this for?  i.e. Full name of class.

"Mobile Computing".
It's a bachelor's degree class here in Roma Tre University (Rome) where i study. Essentially we have to build and deploy a mobile app for grading, choosing between something more graphic-oriented with Corona or more content-oriented with Xamarin. 



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

OK.  I asked because if you are taking a class and the class is about programming, I cannot give solutions, but I can give hints to point you in the right direction.  

 

I personally like to give both in my answers, but I'm sure you can understand that in situations like this, only the latter is acceptable.

 

Let's talk about the issue you're having.

 

1. Apply linear impulse is an instantaneous force.  Its like when you kick a ball, except even faster.  All of the force is applied once and in a single instant, immediately changing the velocity of the ball.  That velocity then bleeds off over time depending on linearDamping, and other factors.

 

2. If you want to hold a button, then release it after a period of time, and if you want that 'hold-delay' to change the magnitude of the impulse, then you need to track the duration of the touch and use that value as part of an equation to modify the y magnitude of your impulse.

 

3. There is another possibility.  You may be confusing applyLinearImpulse() with applyForce().   The latter is meant to be applied every frame over a developer-determined duration to accelerate an object.  You would do this in an enterFrame() listener.



[TOPIC: post.html]
#5

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK


[topic_controls]
[/topic_controls]