Physics: Stop double-jump, but ensure single jump

0 favourites
  • 3 posts
From the Asset Store
Jump on candies, collect candies and earn score!!!
  • Hey all,

    I'm new to Construct 2, and I'm taking a stab at my first real game (after playing with some of the examples, making a few prototypes, etc.). First of all, this is an awesome engine and an awesome community, so thanks to the Scirra crew for making this!

    So, my problem: I have a rolling-platformer type game where I am solely using the "Physics" behavior, not "Platform". The player is a rolling ball, and they can collide with objects (like moveable crates) and platforms (not moveable).

    I want to enable jumping in this game (it's the only real action controlled by the player). Currently, I give the player a neg. Y impulse on key press. However, with this method, if you mash the key, you can do infini-jump, and I want to restrict the player to single jump. That said, I want the player to be able to jump again after they have collided with an object below them (this is key, I don't want you to be able to infini-jump up walls).

    My current implementation is to give the player an instance variable for jump count, defaulted to 0. The player can only jump when jump count == 0. When they jump, I set jump count to 2, and subtract 1 from this value any time the player's velocityY is close to 0 (-1,+1). Ideally, 1 is subtracted at the peak of the jump, and again on ground contact, and this works well in basic terrain situations.

    This does not work well, however, if the player lands on a crate that's on an incline, a sloped platform, etc. It seems like jumping should be possible in these situations, but it's not since the Y velocity hasn't leveled off to 0.

    Is there a better way to restrict to single-jump? I know Platform behavior gives recognition when a sprite touches platforms, is there anything like this for Physics behavior?


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well, of course I just figured this out.

    To anyone interested:

    I used the same jump count instance variable, but I set it to 1 on jump. Instead of decreasing by 1 when the player's velocityY is 0, I now:

    Check for collision with the level objects. I ensure that the objects are below the player before setting jump count to 0. I also ensure that the difference between the X values of the player and the object are close (this prevents wall scaling).


  • Dude, can u upload a capx. file? I only learn with examples... Thanks!

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