Issues with gliding and flying mechanics

Greetings,

In my game, I have two upgrades. One that allows the player to glide, and another that allows the player to fly

I want to make the gliding and flying feel smooth and good to use, thus, I would like for the changes in falling speed to be gradual rather than instant

So this is the code I use:

However, the results are pretty glitchy. If I press the jump button WHILE I’m falling, the gliding and flying works just fine. But if I’m STILL HOLDING the jump button when I start to fall, the states kind of flicker, and the player delays in the air for a short time before gliding or flying

Gliding:

Notice here how the airstate flickers between none and glide. Also notice how the player does this small “hop” before the glide begins

Flying:

Here, notice the airstate flickering again, as well as how the player sort of stalls in midair before flying

Again, this only happens if I continue to hold the jump button when I begin to fall

Can someone please help? How can I remove that “hop” from the glide, and the “stall” from the flying? Do I need to set up the math or the code differently?

Thanks

You have a duplicate “z key is pressed” condition, which immediately sets the variable back to “none”. My guess is you were copying/pasting events and forgot to delete one?

You mean this?

That’s what I thought too, but it’s actually necessary. If that action isn’t there, then the character just takes off into the sky when I start to glide or fly:

Is there another way to fix these issues or simulate gliding and flying properly?

So I decided that in the meantime, it was nigh time to convert my character’s movement system into a finite state machine

I’ve made the conversions, and I seem to have gotten the glide to work the way I want it to with this code:


If the player is falling and holding down the jump button, switch to the glide state

Sadly, another problem arose from it

I have upgrades that let you double jump, but they interfere with the gliding

---------------------WHAT I WANT-------------------------------

I would also like to make it so that you can double jump out of your glide. Basically, if you jump without letting go of the jump button, you glide, but if you let go and press again, you double jump, but only if you have a double jump left. If not, you glide again

---------------------WHAT’S HAPPENING-------------------------------

If the player starts falling or gliding, they are no longer able to double jump. They just glide, even if they have a double jump left

So to try and tell the game when I’m allowed to midair jump, I decided to use this variable system:


Basically, if you’re falling, and the jump button is NOT pressed, then change the variable to TRUE
If we try to jump and the variable is TRUE, double jump, then switch it back to FALSE
If the variable is FALSE, then do the glide or fly instead

However, the bracketed code is the issue. Basically, when we try to jump when the variable is TRUE, it just instantly switches it back to FALSE, and thus, no double jump is performed…

I’ll keep tinkering, but can anybody else let me know how I can change the variable to FALSE without cancelling the jump?

Nvm, I’ve tinkered some more, and I just moved the variable check up here instead:

It works just fine now, thanksss

For the upgrades you requested, your system seemed more complex than necessary. I managed to achieve the same result with just a few events. It does what you needed, though glad you got it working.

Sorry, but I’ve encountered another issue


Basically, if the player tries to perform a midair jump at the exact moment he enters the fall state, the jump is cancelled, and this code block is the culprit

Here, in this GIF, I have the player tinted to indicate if they can midair jump or not. Tinted = TRUE, untinted = FALSE
It might be hard to see here, but you’ll probably notice one single frame at the end of the jump where I’m untinted, and thus, unable to double jump

I absolutely DO need that code there, or else the glide doesn’t work

I’ve tried many different things, like checking how many jumps you had left, checking if the variable is already true, etc, and nothing worked. It feels horrible to control knowing that your jumps can just straight up not work

What can I do? I’ll appreciate any help I can get, thanks

No, that’s not what I meant. But I just realized that the second “z key pressed” condition was actually inverted, so I was wrong anyway :slight_smile:

As for your last question, checking how many jumps are left is what I would do. But I think there’s actually a more fundamental problem here… with a much easier solution.

And that is, you already have this functionality in your behaviors. Or at least, some of it… you’ve got the platformer character behavior and the AdvancedJump behavior, which gives the character the ability to air jump already.

You should be relying on that behavior to handle keeping track of itself. Think of behaviors as a big chunk of events that you don’t have to write yourself. Try to use the behavior’s options to accomplish what you want first. (For example in the AdvancedJump behavior you can set the max number of air jumps, coyote time, and whether jumping from the floor reduces the number of jumps left.)

Now if there’s something the behavior absolutely can’t do by itself, then you can think about extending it using your events. In this case you could do something like this:

(no condition)     |  change maximum falling speed to 100
__________________________________________________________
z key is pressed          |  simulate pressing jump
  -> player can glide?        | change maximum falling speed to 50
  -> player can fly?          | do flying stuff lol

That’s about it! The behavior handles jumping, double jumping, etc… you only have to handle what it doesn’t do, such as change the falling speed based on your inventory.

Thank you for the insight, but I’m already using AdvancedJump to keep track of double jumps. I have code elsewhere that handles all that

And the example you provided is what my code does already, as the behavior doesn’t support gliding:

(no condition)     |  change maximum falling speed to 100
__________________________________________________________
z key is pressed          |  simulate pressing jump
  -> player can glide?        | change maximum falling speed to 50
  -> player can fly?          | do flying stuff lol

That’s how I got to where I am now, I need to find out how to remove this one frame where I can’t midair jump, when the code normally should


EDIT: Upon closer inspection, maybe you’re right. I tinkered some more and replaced the canAirJump variables with the Platformer behavior’s Can Jump condition:


Turns out, it works, and I can just get rid of the variable now!
Although, just one tiny annoyance. If I keep the button held (And can’t glide), the player double jumps automatically. I’d like for it to be manual (Let go of the key, and press again to double jump)
I’m close to getting this, I just need to figure out how to fix this last part


EDIT: Found it


It appears to work now, I really hope it’s fixed this time! Thanks for your input

Now I can’t get the flight to work, I swear I had it working before, but now is just refuses to. The player just stays suspended in midair or falls at a speed of 20. They never ascend

Here’s the fall speed by default:

And here’s the fall speed when the player flies:

Basically, I’d like for my player to gradually build up negative fall speed (Clamped to a minimum value of -200) so that they smoothly build up flight

But it doesn’t matter how big I make the number, the player always insists on descending with a fallspeed of 20

Is there anything else I’m missing?

Alright, I think I got it close?


Basically, I want to have the current fall speed gradually decrease to -200 (Minimum clamp), while not exceeding the max fall speed, to simulate smooth flight

It’s not working right though, it just freezes my current fall speed instead

Do I need to write it differently? Or do I have to do it another way?

A maximum of -200 doesn’t do anything unless the values are under -200. The maximum falling speed is just that, a maximum. If the max fall is 400, then your falling speed cannot exceed 400. Values such as -200, 0, and +200 will be accepted. A value of 401 would be limited back down to 400.

What you want is a minimum fall speed. You could do this with a simple event that says if fall speed is less than -200, set fall speed to -200. (whether to include check if player is flying would be up to you, if you don’t check that then this will limit your upward speed in general)

The clamp instruction doesn’t make any sense. The maximum fall speed should be set to one value for normal jumping, and one value for gliding, that’s it. Again, it won’t have anything to do with flying since negative values will always be less than the maximum fall.

1 Like