Player jump action stopped working after I meddled with tilemap tile placement

Godot Version

<godot4.2.1>

Question

Code was working completely fine aka the jumping worked, then I decided to place some tiles. After I placed said tiles I ran the current scene and saw that my left and right movement was fine, I could fall aka gravity worked, but for some reason now I couldn’t jump.

This is the only code I use (It is from a tutorial)

extends CharacterBody2D


@export var speed : float = 200.0
@export var jump_velocity : float = -200.0
@export var double_jump_velocity : float = -200.0

@onready var animated_sprite : AnimatedSprite2D = $AnimatedSprite2D

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var has_double_jump : bool = false
var animation_locked : bool = false
var direction : Vector2 = Vector2.ZERO
var was_in_air : bool = false

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta
		was_in_air = true
	else:
		has_double_jump = false
		
		if was_in_air == true:
			land()
			
		was_in_air = false

	# Handle jump.
	if Input.is_action_just_pressed("jump"):
		if is_on_floor():
			jump()
		elif not has_double_jump:
			double_jump()
			
		
	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	direction = Input.get_vector("left", "right", "up", "down")
	if direction.x != 0:
		velocity.x = direction.x * speed
	else:
		velocity.x = move_toward(velocity.x, 0, speed)

	move_and_slide()
	update_animation()
	update_facing_direction()

func update_animation():
	if not animation_locked:
		if not is_on_floor():
			animated_sprite.play("jump_loop")
		else:
			if direction.x != 0:
				animated_sprite.play("run")
			else:
				animated_sprite.play("idle")

func update_facing_direction():
	if direction.x > 0:
		animated_sprite.flip_h = false
	elif direction.x < 0:
		animated_sprite.flip_h = true

func jump():
	velocity.y = jump_velocity
	animated_sprite.play("jump_start")
	animation_locked = true

func double_jump():
	velocity.y = double_jump_velocity
	animated_sprite.play("jump_double")
	animation_locked = true
	has_double_jump = true
	
func land():
	animated_sprite.play("jump_end")
	animation_locked = true


func _on_animated_sprite_2d_animation_finished():
	if(["jump_end", "jump_start", "jump_double"].has(animated_sprite.animation)):
		animation_locked = false
	


No clue, it looks correct. Post your project or more detail.

1 Like

Check your exports. You may have accidentally reset them.

1 Like

Could it be that the new tiles dont have the same properties as the tiles you used previously? Maybe collision layers or other things you did in the tutorial for the first tiles used.

Put a print('jump') in the jump()-function to see if it is being called at all.

1 Like

OK. So I found the solution. Its the dumbest thing ever that took me 3 days to find.
For some reason, MAGICALLY, the jump input map somehow unbinded itself. Thank you.

I will be taking notes

Glad you sorted it out! Sometimes the dumbest bugs are the hardest to find… Printing some debug lines is a great first got-to.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.