My jump stops in mid-air

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

I am using if Input.is_action_pressed for my controls. When i run my characters stops moving when i release the button, but i actually want my jump to continue in the same direction when i let my button go, until it hits a collision.

if Input.is_action_pressed("ui_right"):
	motion.x = SPEED
	$Sprite.flip_h = false
	if is_on_floor():
		$Sprite.play("Run")
	else:
		$Sprite.play("Flip")

I could use some tips on how to achieve this. The speed is a constant of 240, thats what i want to maintain, should be really simple for most i assume.

:bust_in_silhouette: Reply From: Socrates

There are a lot of way to do this. One would be to create a state variable that keeps track of whether the character is jumping, running, standing, etc. Then when the character is jumping motion.x always equals SPEED. Use Input.is_action_just_pressed() for the jump control and when that’s pressed, if the character is on the floor, change the state to jumping.

The “flip” animation is for sideways jumping and as soon as it get’s airborne it’s starts “flipping” until it hits the ground.

	if Input.is_action_just_pressed("ui_jump"):
	if is_on_floor():
		motion.y = JUMP_HEIGHT
		$Sprite.play("Jump")

When i press left or right in the air it will go automatically from my “jump” sprite into my “flip” animation until it hit’s a floor collision wich will return my “Idle” sprite. Sideways direction and speed is managed by ui_right & ui_left.

I don’t know to write code yet, i’m a copypasta programmer, do you have some examples for me to look at?

KND2501 | 2018-03-05 21:30