0 Favourites

Variable height jump with physics?

  • Just a quick question.

    I am using physics to make a platformer game. However I am not sure how to accomplish variable height jumps with physics (as in a long press means you jump higher than a short tap).

    Basically it should work like this.

    As you press space you apply an 'impulse' and immediately start ascending and decelerating. However whenever space is released, the vertical velocity needs to completely stop (i.e. advancing the deceleration).

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • maybe while space is pressed add force a couple of seconds? , if you stop vertical velocity, it will stop moving abruptly, you should let the gravity control this

  • I think you can use the same trick as what I use with the platform behavior

    set a JumpCap instance variable (the value should be tweaked by trial and error)

    and in event

    Keyboard: [invert] Space is down
    LocalYVelocity < JumpCap
        -> set LocalYVelocity to JumpCap

    Of course, you will have to calculate this LocalYVelocity which is a projection of the world-space velocity to the player object-space (or player-space).

    And then you will have to convert the set LocalYVelocity back to world-space :D (lots of fun isn'it?)

    Well if you look at the last capx I cooked for you you might find some ways

    By the way, it's < JumpCap and JumpCap should be negative. It's the Vertical velocity you want your player to have if you release space and you're still under its value (which means you're still going up in player space). You don't cap to 0 to avoid too sharp transition but to a low negative value.

  • Been trying to get this behaviour working as well. Any chance I could get to take a look at the capx?

  • I think the easiest way to do this is use impulse and every time you hit a key, eg. space, apply the impulse to your character

  • Yes, Construct 2 is missing "Jumping Peak", what is common in my other game makers.

  • I think the way yann is describing it is the way I'd like to use it. just not exactly sure how to implement it at this stage. I sort of understand how to do it and will have fiddle around with it a bit later but I suspect my way of doing it wouldn't work so that's why I'm asking if he could share the capx with the rest of the community. :)

  • Well I did it by changing the behavior of the character from Physics to Platform.

    Then, whenever space is released, and vectorY < 0, set vectorY to vectorY / 2.

  • That worked wonders. Thanks for sharing. :)

  • No problem ;)

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