Simple code stops Platformer from jumping sometimes

0 favourites
  • 4 posts
From the Asset Store
10 Retro songs ideal for platformers or farming games
  • Ok so I wanted to make a "Pre-Jump" mechanic, where if you press jump slightly before you hit the ground, you will jump as soon as you land.

    Code is very simple:

    If you press jump button while platform is not on ground - set "PreJump" value to 30

    If PreJump is greater than 0 - Subtract 1 from PreJump

    If Player is on ground and PreJump is greater than 0 - Jump

    This almost always works no problem. Sometimes though, if I press Jump while in the air, not only will the object not jump on landing, but will then not be able to jump at all until the "PreJump" value reaches 0. (Tested in debug mode)

    I recreated this in a blank project with just a Player object and ground and it still happens.

    I can't seem to force it to happen, and usually have to just spam jump to get it to trigger. Sometimes it feels like holding jump right before landing effects it, but it's hard to tell.

    Screencap of code: imgur.com/cNAWFdn

    Anybody know what might be happening?

    Tagged:

  • "If Player is on ground and PreJump is greater than 0 - Jump". This should be trigger once ideally but you have it running every tick while variable > 0. You could gain more control over it by using 'on landed' which is trigger once, with variable > 0 condition.

  • Hey thanks for the response, this appears to have fixed it.

    However there are times when I'm jumping around a lot on platforms and I swear I press the jump button and it just doesn't register.

    This happens even without my "PreJump" mechanic being turned on. I know sometimes I'm just pressing jump too soon before landing but other times I swear I see my walking animation before pressing it and it just doesn't register.

    Has anyone else experienced this? Am I just not timing it well enough?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is it set to show a walk animation when you land? Share a playable of the game to demonstrate it.

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