Player (Adam) not jumping when pressing left and up at the same time!

Godot Version

v4.3.stable.official [77dcf97d8]

Question

Hi Forum!!

So below is the code I have for my 2d beat em up game like Street of Rage 4!

Now I have the jumping working but when holding left and up (to walk left upwards at the same time) and then press jump the character never jumps. Now if I hold right and up (to walk right and upwards at the same time) it works the character jumps. If I hold left and jump works, If I hold up and jump it jumps, etc. Is just only when holding left and up at the same time that the player is not jumping.


# Variables
@export var speed := 250
@export var jump_height := 200 # Adjust this value to increase jump height
@export var jump_duration := 0.5 # Total time to reach peak and come back down
@onready var adam_animated_sprite = $AnimatedSprite2D
@export var jabbing := false
@export var uppercutting := false
@export var is_jumping := false

var target_velocity = Vector2.ZERO # Used for smoothing velocity
var jump_timer = 0.0 # Timer to track jump progress
var start_y_position = 0.0 # The Y position before jump starts

# This code controls the up, down, right, and left movement of the Character.
@warning_ignore("unused_parameter")
func _process(delta: float) -> void:
	var direction = Vector2.ZERO  # Define direction here so it’s always in scope
	
# Check if jab is triggered and set jabbing to true
	if Input.is_action_just_pressed("Jab") and not jabbing:
		jab()
	
# Prevent movement if jabbing
	if jabbing:
		velocity = Vector2.ZERO  # Stop movement when jabbing
	else:
		# Prevent movement while jumping
		if not is_jumping:
			direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
			# Use lerp to smoothly change the velocity
			target_velocity = direction * speed
			velocity = velocity.lerp(target_velocity, 0.3)

			# Flip sprite based on direction
			if direction.x != 0:
				adam_animated_sprite.flip_h = direction.x < 0

	# Handle jump input
		if Input.is_action_just_pressed("ui_select") and not is_jumping:
			jump()

		# Handle jumping movement
		if is_jumping:
			jump_timer += delta
			var jump_progress = jump_timer / jump_duration

			# Apply the jump arc
			if jump_progress < 1.0:
				# Move up, then down by adjusting Y position based on jump progress
				position.y = start_y_position - jump_height * sin(jump_progress * PI)
			else:
				# End the jump
				is_jumping = false
				position.y = start_y_position # Reset to ground level

# Apply the updated velocity to move the character only if not jabbing
	if not jabbing:
		move_and_slide()

	play_animations(direction)

# This code controls the animations when jabbing, jumping, walking, and idle.
func play_animations(dir):
	if jabbing:
		adam_animated_sprite.play("Jab")
	elif is_jumping:
		adam_animated_sprite.play("Jumping")
	else:
		if dir.length() > 0:
			adam_animated_sprite.play("Walking")
		else:
			adam_animated_sprite.play("Idle")

# Function to handle jabbing action
func jab():
	jabbing = true
	adam_animated_sprite.play("Jab")
	await adam_animated_sprite.animation_finished  # Wait for the jab animation to finish
	jabbing = false

# Jump function to start the jump
func jump():
	is_jumping = true
	jump_timer = 0.0
	start_y_position = position.y # Record the ground level Y position before jump

I did had a print to whenever we press jump! It prints isJumping on all the other directions but when holding left and up at the same time and pressing jump it does not print isJumping. Any Ideas been looking at the code but I got no Idea why!!!

If you are using keyboard, then possible it can’t process any more input when these two key (for left and up) pressed simultaneously. Try remapping directional keys or or jump key.
There should be no problem on controller.

1 Like

Oh yes sorry!! I am using Keyboard have not connected a controller yet!

Thanks will try!!

Ok noob question hahaha I am still a beginner in GODOT. I know to go to the input manager and do it from there, but for example the Jump is already attached to the Space bar (ui_select), how would I remap it?

I did add a input manager called Jump and attached the space bar key but still not jumping to that specific side.

There is toggle on input map called “Show built-in Actions”. You can edit default mapping there.
And SPACE does not work well with arrow keys on some keyboards.

Ohh nice to know!!! Thanks will do at some point today will let you know!!!

Last question lol!

Ok let say I mapped the Keyboard Key H called Jump! Do I need to remove whatever is under ui_select?

Also The same for ui up, left, right and down?

Thanks again!

You use the name of action in your input check, so if you called your action “Jump”:

if Input.is_action_just_pressed("Jump"): jump_function()

or

if Input.is_action_pressed("Jump"): jump_function()

No need to touch default mapping, only if you plan to remap everything.

Ok so this is what I did. I mapped the up, down, left and right to to be the arrow keys only and removed everything else. Mapped the Jump to be the Key B instead of space and remove everything else.

ui_up = up arrow key
ui_down = down arrow key
ui_left = left arror key
ui_right = Right arrow key
ui_select = B
Jabbing = J

Now I also tried and added

left = left arrow key.
right = right arrow key.
up = up arrow key.
down = down arrow key.
Jump = B key
Jabbing = J Key

Still the player can not jump to that left/up side. Could be I did something wrong on the mapping IDK but that is how I mapped them to test it out.

Thanks,

ok I did change the “Jump” to be ui_select, what I would try now is to change the function to jump_funtion to see

No need to copy my example.
Remap you keyboard keys to different ones. Instead of arrow keys use WSAD.

1 Like

Ok change the jump() to be jump_function() and also did the same with jabbing, instead of jab() using jab_function() that should clear somethings lol.

Ahhh still can not jump that way!! Btw thanks for the help! means a lot!

No need to change your code, just remap “ui_left”, “ui_right”, “ui_up”, “ui_down” from arrow keys to different keyboard keys in “Input Map” that’s all.

DING DING DING DING!!! man has soon has I remapped the ui_up, ui_down, ui_left, ui_right to be WSAD!! NOW I can jump!!! but what if I want to use the arrow keys?

All keyboards are different, so you can’t know what key combinations will work.
Consider adding custom key remapping for player in future.

That makes sense!! I will use WSAD from now on.

Thanks you!!

1 Like

I personally use for arcade layout: RFDG for direction and JKL for action, works fine on most keyboards. And again, joypads don’t have this problem, you can press all buttons at the same time.

1 Like

I was planning on doing a beat em up but smashing pressing for example pressing J one time does a jab, pressing j two times then does an uppercut, but I could also do J for jabbing, K for Kick and L for uppercut, don’t know how would this influence the beat em up style.