(I was trying to make a state machine and learn about it)
so my idle state switches to move state if the player is moving, and it switches to jump state if jump is pressed. (the move state is almost the same.)
class_name Jump
extends State
@onready var anim: AnimationPlayer = get_parent().get_parent().find_child("AnimationPlayer")
@onready var player: CharacterBody2D = get_parent().get_parent()
func physics_uodate(_delta: float):
if Input.is_action_just_released("jump"):
if !player.direction:
pstate_machine.transition_to("Idle")
else:
pstate_machine.transition_to("Move")
if player.direction:
player.move(90, 600, _delta)
player.jump(-90)
else:
player.move(0, 600, _delta)
player.jump(-90)
player.move_and_slide()
(The if player.direction stuff on the bottom is for the player being able to move even while jumping.)
And when I long press I fly.
(And yes, I did add a if is_on_floor() then jump.)
You spelled physics_update as physics_uodate. I’m not sure how this code is working at all TBH. However, ignoring that, you are calling jump() every physics frame. You should call it once when the jump button is pressed. Not every frame. That’s why you’re flying.