how to prevent player switching direction during mid-air jump?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By chris33556

im trying to implement a player jumping without the character changing direction in mid-air. Now, ive seen a similar post however the difference is that my script is not using the “on_ground” or “floor” detect. it uses the x axis position to determine the floor.

can someone explain where and what code I would need to implement the solution. just to be clear here is a link to the video demonstrating the problem:

via GIPHY

and here is the code:

https://pastebin.com/GHYgV81J

id appreciate any advice and solutions thank you

:bust_in_silhouette: Reply From: Inces
func _physics_process(delta):
	var axis = get_input_axis()
	print(Jumping)
if axis == Vector2.ZERO:
		if  Jumping == false:
			animatedSprite.animation = "Cap_off_idle"
		    apply_friction(ACCELERATION * delta)
	else:
		if  Jumping == false:
			animatedSprite.animation = "WalkRight"
		    apply_movement(axis * ACCELERATION * delta)

All I did there was indent movement lines to the right, so they are under condition of jumping being false. If I understood your code correctly, that means moving will not be allowed when in the air

Thanks for your response. the sprite still changes in mid-air.
However i posted a similar question in Reddit and received a few answers whereby placing
in line 57 : “if !Jumping” as well as indenting lines 58 & 59 - fixed the mid-air movement problem and with your advice on moving code to the right it solved the problem. this is the result :

Godot GIF - Find & Share on GIPHY

Many thanks for your help!

chris33556 | 2022-05-22 07:49