Jump on specific tempo ?

  • Hi,

    In order to make a rythmic game, I would like to make a sprite jump in a very precise timing.

    Let's say I want the Jump to be 500 pixels high and 1 second long.

    Is there a way to define "Jump Strenght" and "Gravity" for this ? Like a sort of equation ?

    Thanks !

  • For precision movement over time, I like to lerp a set origin and destination over a timer duration. You'll need the timer behavior, and two instance variables for the original position and the destination position.

    For the jump gravity motion, a simple inverted quadratic equation should simulate it fairly well. It would be y=1-4(x-0.5)^2 in this case, where the x value of lerp will go up to 1 and back down to 0 on a parabolic curve based on the amount of time passed over the total timer duration.

    Here is what the events should look like:

    + Keyboard: On any key pressed

    + Sprite: [X] Is Timer "jump" running

    -> Sprite: Start Timer "jump" for 1.0 (Once)

    -> Sprite: Set OriginY to Self.Y

    -> Sprite: Set TargetY to Self.Y-100

    + Sprite: Is Timer "jump" running

    -> Sprite: Set Y to lerp(Sprite.OriginY,Sprite.TargetY,1-4×(Sprite.Timer.CurrentTime("jump")÷Sprite.Timer.Duration("jump")-0.5)^2)

    The qarp expression could probably be used to simplify the equation but I never really wrapped my head around it... It could probably also be useful if you wanted to fine tune the motion.

  • Wow Thanks ! This is helpfull

    But I don't get this line :

    + Sprite: [X] Is Timer "jump" running

    I didn't write it and it seems to work...

    You said it would be possible to fine tune using qarp, I'm researching this way but... is someone knows about that ?

  • Like for exemple if I want this kind of curve :

    Timer = 0 Sprite.Y = 500

    Timer = 0.25 Sprite.Y = 200

    Timer = 0.5 Sprite.Y = 0

    Timer = 0.75 Sprite.Y = 200

    Timer = 1 Sprite.Y = 500

    Or with variables that it can be ajustable...

    Thanks !!

  • Wow Thanks ! This is helpfull

    But I don't get this line :

    + Sprite: [X] Is Timer "jump" running

    I didn't write it and it seems to work...

    You said it would be possible to fine tune using qarp, I'm researching this way but... is someone knows about that ?

    This is just an added condition so that if the timer is already running, you can't jump again until it is over. Right click and set inverse. Basically means Is Timer "jump" NOT running.

    It should work if you don't have it, but you'll just be able to keep jumping even when you're in the air.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Like for exemple if I want this kind of curve :

    Timer = 0 Sprite.Y = 500

    Timer = 0.25 Sprite.Y = 200

    Timer = 0.5 Sprite.Y = 0

    Timer = 0.75 Sprite.Y = 200

    Timer = 1 Sprite.Y = 500

    Or with variables that it can be ajustable...

    Thanks !!

    The formula I gave you should already be very close to numbers you described. Just change the TargetY to -500 instead of -100.

    -> Sprite: Set TargetY to Self.Y-100

    to

    -> Sprite: Set TargetY to Self.Y-500

  • Hummm yes, you are right, but I would like to control a third point of the curve to ajust the rythm of the jump.

  • 1-16(x-0.5)^4 will give you more hangtime, but is a bit unnatural.

    (x=(Sprite.Timer.CurrentTime("jump")÷Sprite.Timer.Duration("jump"))

  • Cool !

    I'm now messing around with numbers, but still don't get the logic...

    Is there a formula more close to a sinus, but still a parabola ?

    Thanks

  • A sinus?

    Try sin(pi*x).

  • Haha, thanks.

  • I found it !

    Using a third instance variable and the qarp() function, I can manage to have more control for shaping my curve.

    Your formula is doing great job for the timing. I'm good to go

    Thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)