From bb3b75929a4e4307dd3eb1ba82dc6f39b8e8324a Mon Sep 17 00:00:00 2001 From: teatov Date: Thu, 13 Feb 2025 23:35:49 +1000 Subject: [PATCH] return jumping to `_physics_process` --- scripts/player.gd | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/player.gd b/scripts/player.gd index 9a9dd3f..4a58222 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -79,6 +79,8 @@ func _physics_process(delta: float) -> void: _lateral_movement(delta) _vertical_movement(delta) + _jumping() + move_and_slide() @@ -92,9 +94,6 @@ func _unhandled_input(event: InputEvent) -> void: if event is InputEventMouseMotion: _handle_mouse_rotating(event as InputEventMouseMotion) - if event.is_action_pressed("jump"): - _jump() - if event.is_action_pressed("crouch"): _crouch = true if event.is_action_released("crouch"): @@ -202,6 +201,15 @@ func _vertical_movement(delta: float) -> void: velocity.y = 0 +func _jumping() -> void: + if ( + Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED + and Input.is_action_just_pressed("jump") + and is_on_floor() + ): + velocity.y = JUMP_FORCE + + func _handle_mouse_rotating(event: InputEventMouseMotion) -> void: var sensitivity := deg_to_rad(Settings.mouse_sensitivity) @@ -223,11 +231,6 @@ func _handle_mouse_rotating(event: InputEventMouseMotion) -> void: _camera.rotation.x = clamp(_camera.rotation.x, -PI / 2, PI / 2) -func _jump() -> void: - if is_on_floor(): - velocity.y = JUMP_FORCE - - func _on_networker_player_registered(peer_id: int, player_info: Dictionary) -> void: if peer_id != _peer_id: return