Hi there, here is my jump function.
I'm having a very strange issue where if my character falls from a very tall height, he will fall, but stop in mid air, then continue to fall. I'm using moveandslide in my physics process function if that helps.
Oddly enough, I have a friction function that doesn't seem to apply friction either. However I've disabled it to make sure that wasn't the cause, and it wasn't.
PS. I know I have two isonfloor checks, I'll fix that later, but at the moment, that isn't the issue either. I've disabled the second one and I still had the issue.
I thought it might be the delta but I'm not entirely sure how to use it.

Many thanks!

``````func jump(delta):
if is_on_floor():
jumps_left = 2
elif next_to_wall():
jumps_left = 1

if Input.is_action_just_pressed("up") and jumps_left > 0:
#if I'm falling - ignore fall velocity
if velocity.y > 0:
velocity.y = 0
velocity.y = JUMP_POWER
jumps_left -= 1
#wall jump
if not is_on_floor() and next_to_left_wall():
velocity.x += JUMP_POWER
if not is_on_floor() and next_to_right_wall():
velocity.x -= JUMP_POWER

#if still jumping, start to fall
if Input.is_action_just_released("up") and velocity.y < 0:
velocity.y *= FALL_SPEED
on_ground = false

if is_on_floor():
if on_ground == false:
is_attacking = false
on_ground = true
else:
if is_attacking == false:
on_ground = false
\$Sprite.play("spinning")
else:
velocity = Vector2()
``````

Edit: Hi guys, I've done some further testing and have found that when it reaches a specific number (1953 or 1955), for some reason it resets to 1 immediately after, which is causing me to suddenly stop in mid air for a second.

EDIT: FOUND THE ISSUE!!!
I have a gravity function (that I copy and pasted from a tutorial) that clamps the falling speed if it hits 2000. Ha....

``````func gravity():
if not dashing:
velocity.y += GRAVITY
``````

## velocity.y = 0 #clamp falling speed

``````if next_to_wall() and velocity.y > MAX_WALL_SLIDE_SPEED and (Input.is_action_pressed("right") or Input.is_action_pressed("left")):
velocity.y = MAX_WALL_SLIDE_SPEED #wall slide
``````
in Engine
edited

There is no need to set velocity to 0 before changing it to jump power, because if it was at 60, then you change it to 0, then to -100 for example, that is no different that just changing it directly. I'm not sure, but that could be part of your problem. I hope this helps, but I'm not sure.

by (586 points)

I commented it out and unfortunately still have the same issue.

I suspected it has to do with velocity randomly being reset, so I put a print statement to print out the velocity values.

For some reason, whenever it hits 1953 or 1955, it resets to 1, which is why I kinda freeze in mid-air, because it's recalculating falling.