diff --git a/scripts/player.gd b/scripts/player.gd index 165a0e6..5f5b65c 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -28,9 +28,16 @@ func _physics_process(delta): # As good practice, you should replace UI actions with custom gameplay actions. handle_input() handle_movement(delta) + update_states() move_and_slide() handle_collisions() - + +#Create a State Machine.........t.w. +func update_states()->void: + match current_state: + State.JUMP when velocity.y >0: + current_state = State.FALLING + func handle_input()->void: # Handle jump. if Input.is_action_just_pressed("jump") and is_on_floor(): @@ -79,8 +86,6 @@ func handle_movement(_delta)->void: if current_state == State.JUMP: #apply normal velocity velocity += get_gravity() * _delta - if velocity.y>0: - current_state = State.FALLING else: #apply hard gravity, character falling velocity += get_gravity() * hard_gravity * _delta