why i cant jump when i am moving

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

hello i am trying to make a character using a ridgidbody2d and i made this script

 extends RigidBody2D

func _integrate_forces(state: Physics2DDirectBodyState) -> void:
	if Input.is_action_just_pressed("ui_up"):
		add_force(Vector2(1 , 1), Vector2(0,-14000))
	elif Input.is_action_pressed("ui_right"):
		add_force(Vector2(1 , 1), Vector2(50,00))	
	elif Input.is_action_pressed("ui_left"):
		add_force(Vector2(1 , 1), Vector2(-50,0))
	else: 
		set_applied_force(Vector2(0 , 0))

		
	if get_applied_force() > Vector2(1000, 0):
		set_applied_force(Vector2(1000, 0 ))
	if get_applied_force()  <= Vector2(-1000, 0):
		set_applied_force(Vector2(-1000, 0 ))
		pass

but when i try to jump when i am moving it dont work

thank you in advance for your help

:bust_in_silhouette: Reply From: timothybrentwood
if Input.is_action_just_pressed("ui_up"):
    add_force(Vector2(1 , 1), Vector2(0,-14000))
elif Input.is_action_pressed("ui_right"):

If you pressed the up key then the first condition fires and the code continues after that if block. The next executed line is if get_applied_force() > Vector2(1000, 0):

Change elif Input.is_action_pressed("ui_right"): to if Input.is_action_pressed("ui_right"): and you will be able to move and jump at the same time. But note that the logic of your if statement has changed because theelse clause no longer cares about the state of the "ui_up" input.

As a side note, consider making your character a KinematicBody2D node.