- _process_camera(delta)
- _process_player(delta)
-
-
-# Get the XZ input direction based on player's input relative to the camera
-func _get_player_move_direction() -> Vector3:
- var input_dir := Input.get_vector("player-left", "player-right", "player-forward", "player-backward")
- var forward := _camera.global_basis.z
- var right := _camera.global_basis.x
- var move_direction := (forward * input_dir.y + right * input_dir.x).normalized()
- move_direction.y = 0
- return move_direction
-
-
-func _process_camera(delta: float) -> void:
- # vertical camera rotation
- _camera_pivot.rotation.x += _camera_input_direction.y * mouse_sensitivity_y * delta
- _camera_pivot.rotation.x = clamp(_camera_pivot.rotation.x, -PI / 6, PI / 3)
-
- # horizontal camera rotation
- _camera_pivot.rotation.y -= _camera_input_direction.x * mouse_sensitivity_x * delta
-
- # reset mouse movement vector if mouse input
- if _camera_input_method == CAMERA_MOUSE_INPUT:
- _camera_input_direction = Vector2.ZERO
-
- # change spring length depending on player speed
- _camera_spring.spring_length = lerp(
- _camera_spring.spring_length, camera_distance + velocity.length() / 4, delta
- )
-
-
-func _process_player_on_floor(delta: float):
- var move_direction := _get_player_move_direction()
-
- # if we're not stuck, then it's okay to set the velocity
- _floor_normal = get_floor_normal()
- _ground_slope_input = (PI / 2) - velocity.angle_to(_floor_normal)
- velocity = velocity.move_toward(
- move_direction * (_player_speed + _ground_slope_input * _player_speed),
- acceleration * delta
- )
- var movement_speed := Vector3(velocity.x, 0, velocity.z).length()