My charecter dose no jumps

Godot Version

4.6 stable

Help:

ma player dos not jump (i am a bad coder)

i got the input map and it prints jump on state change.

extends CharacterBody2D


enum State {
	IDLE,
	WALK,
	JUMP,
	FALL,
	#ATACK,
	#DASH_ATACK
}
var current_state = State.IDLE

@export var move_speed: int = 180
@export var jump_force: int = 300
@export var dash_force: int = 200
@export var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")

@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D


func _physics_process(delta: float) -> void:
# Aply gravity
	if not is_on_floor():
		velocity.y += gravity * delta

# Get input
	var direction = (+Input.get_action_strength("Right")
	-Input.get_action_strength("Left"))

# State Machine
	match current_state: 
		State.IDLE:
			velocity.x = 0
			if direction != 0:
				change_state(State.WALK)
			if Input.is_action_just_pressed("Jump") and is_on_floor():
				change_state(State.JUMP)
			#if Input.is_action_just_pressed("Atack"):
				#change_state(State.ATACK)

		State.WALK:
			velocity.x = direction * move_speed
			if direction == 0:
				change_state(State.IDLE)
			if Input.is_action_just_pressed("Jump") and is_on_floor():
				change_state(State.JUMP)
			#if Input.is_action_just_pressed("Atack"):
				#change_state(State.DASH_ATACK)

		State.JUMP:
			velocity.x = direction * move_speed
			if velocity.y > 0:
				change_state(State.FALL)

		State.FALL:
			velocity.x = direction * move_speed
			if is_on_floor():
				change_state(State.IDLE)


	move_and_slide()


func change_state(new_state: State):
	# Exit current state
	match current_state:
		State.JUMP:
			pass  # Could stop jump animation


	current_state = new_state

 # Enter new state
	match new_state:
		State.JUMP:
			print("jump")
			velocity.y *= jump_force
			animated_sprite.play("jump")
		State.IDLE:
			print("idle")
			animated_sprite.play("idle")
		State.WALK:
			print("walk")
			animated_sprite.play("walk")
		State.FALL:
			print ("fall")
			animated_sprite.play("fall")

Thanks in advice :slight_smile:

If your y velocity is zero when you jump it’ll remain zero. Try adding your jump force instead of multiplying it.

velocity.y += jump_force

This is how it was before and it dit not worket too.

I tried it again and it did not worket. : (

Btw is this code clean?

What is jump_force set to in the editor?

it is now set to 800 both in script and editor.

hes correct multiplying a zero y velocity to your jump force is like making a useless if condition that has the longest condition in humanity, and it just passes after

its nice it can be cleaner though

Okay but how?

btw it is stil not working with jump_force = 8000

I got it.

velocity.y -= jump_force

the player will be in the backrooms
make it +=

and IF u going with -= u gotta make jump force negative like this: velocity.y = -jump_force, or like this: jump_force = -800(or whatever nummber u want should be negative)