2026-08-09 03:24:28 +02:00
|
|
|
class_name ProceduralAnimator extends Node
|
2026-07-29 00:05:40 +02:00
|
|
|
|
2026-08-09 03:24:28 +02:00
|
|
|
@export var player: Player
|
|
|
|
|
@export var camera: Camera3D
|
|
|
|
|
@export var ui: Control
|
|
|
|
|
@export var movement: Node
|
2026-07-29 00:05:40 +02:00
|
|
|
|
2026-08-09 03:24:28 +02:00
|
|
|
@onready var ui_base_position = ui.position
|
2026-08-02 16:19:24 +02:00
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
var t_bob: float = 0.0
|
|
|
|
|
var last_bob_y: float = 0.0
|
2026-07-29 13:52:14 +02:00
|
|
|
var t_breath: float = 0.0
|
|
|
|
|
var last_breath_y: float = 0.0
|
2026-08-07 15:50:27 +02:00
|
|
|
var target_rotation: Vector3 = Vector3.ZERO
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
var _last_camera_global_position: Vector3 = Vector3.ZERO
|
2026-07-29 13:52:14 +02:00
|
|
|
var _breathing: bool = true
|
2026-07-29 00:05:40 +02:00
|
|
|
|
2026-08-09 03:24:28 +02:00
|
|
|
#signals for emitting sounds
|
|
|
|
|
signal footstep
|
|
|
|
|
signal breath(breathe_in:bool)
|
|
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
func _ready() -> void:
|
|
|
|
|
_last_camera_global_position = camera.global_position
|
|
|
|
|
|
2026-08-09 03:24:28 +02:00
|
|
|
func _physics_process(_delta: float) -> void:
|
|
|
|
|
camera.rotation += target_rotation
|
|
|
|
|
|
2026-07-29 13:52:14 +02:00
|
|
|
func _process(delta: float) -> void:
|
2026-08-09 03:24:28 +02:00
|
|
|
if not UiManager.in_game_menu.visible:
|
|
|
|
|
do(delta)
|
|
|
|
|
if player.is_on_floor():
|
|
|
|
|
_breathing = true
|
|
|
|
|
else:
|
|
|
|
|
_breathing = false
|
|
|
|
|
|
|
|
|
|
footstep_sound()
|
|
|
|
|
breathing_sound()
|
2026-07-29 13:52:14 +02:00
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
func do(delta):
|
2026-08-02 16:19:24 +02:00
|
|
|
ui.offset_transform_scale *= PlayerConsts.UI_SCALE
|
2026-07-29 00:05:40 +02:00
|
|
|
ui_movement_handling(delta)
|
2026-07-30 01:44:27 +02:00
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
var horizontal_speed = Vector3(player.velocity.x, player.velocity.y, player.velocity.z).length()
|
|
|
|
|
|
2026-07-30 01:44:27 +02:00
|
|
|
if _breathing:
|
2026-08-09 03:24:28 +02:00
|
|
|
t_breath += delta * (100 / (40 + player.stamina_component.stamina))
|
2026-07-30 01:44:27 +02:00
|
|
|
|
|
|
|
|
var target_pos = get_breathing_bob_offset_pos()
|
|
|
|
|
var target_rot = get_breathing_bob_offset_rot()
|
2026-07-29 02:37:45 +02:00
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
if player.is_on_floor() and horizontal_speed > 0.05:
|
|
|
|
|
t_bob += delta * (player.velocity.length() * float(player.is_on_floor()) + (int(Input.is_action_pressed("crouch"))) * 3)
|
|
|
|
|
|
2026-07-30 01:44:27 +02:00
|
|
|
target_pos += get_moving_bob_offset_pos()
|
|
|
|
|
target_rot += get_moving_bob_offset_rot()
|
2026-07-29 00:05:40 +02:00
|
|
|
|
2026-07-30 01:44:27 +02:00
|
|
|
camera.transform.origin = camera.transform.origin.lerp(target_pos, delta * 10)
|
|
|
|
|
|
2026-08-07 15:50:27 +02:00
|
|
|
var final_pitch = target_rot.x
|
2026-07-30 01:44:27 +02:00
|
|
|
var final_roll = target_rot.z
|
|
|
|
|
|
2026-08-09 03:24:28 +02:00
|
|
|
#var target_basis = Basis.from_euler(Vector3(final_pitch, 0, final_roll))
|
2026-07-30 01:44:27 +02:00
|
|
|
|
2026-08-07 15:50:27 +02:00
|
|
|
target_rotation = Vector3(final_pitch, 0, final_roll)
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
func ui_movement_handling(delta: float):
|
2026-08-09 03:24:28 +02:00
|
|
|
var mouse_offset = -movement.mouse_motion_delta * PlayerConsts.UI_MOVEMENT_SENSITIVITY
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
var current_camera_global_position = camera.global_position
|
|
|
|
|
var camera_global_velocity = (current_camera_global_position - _last_camera_global_position) / delta
|
|
|
|
|
|
|
|
|
|
var cam_local_vel = camera.global_transform.basis.inverse() * camera_global_velocity
|
|
|
|
|
|
|
|
|
|
var inertia_offset = Vector2(
|
|
|
|
|
-cam_local_vel.x,
|
|
|
|
|
cam_local_vel.y - (cam_local_vel.z * 0.25)
|
2026-08-02 16:19:24 +02:00
|
|
|
) * PlayerConsts.CAMERA_VELOCITY_MULTIPLIER
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
var target_offset = mouse_offset + inertia_offset
|
2026-08-02 16:19:24 +02:00
|
|
|
ui.position = ui.position.lerp(ui_base_position + target_offset, delta * PlayerConsts.UI_MOVEMENT_SPEED)
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
_last_camera_global_position = current_camera_global_position
|
|
|
|
|
|
2026-08-02 16:19:24 +02:00
|
|
|
var ui_scaling_target = Vector2(-cam_local_vel.z * PlayerConsts.UI_MOVEMENT_SENSITIVITY * .002 + 1, -cam_local_vel.z * PlayerConsts.UI_MOVEMENT_SENSITIVITY * .002 + 1)
|
|
|
|
|
ui.offset_transform_scale = ui.offset_transform_scale.lerp(ui_scaling_target, delta * PlayerConsts.UI_MOVEMENT_SPEED)
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
var ui_rotation_target = -inertia_offset.x - mouse_offset.x * 0.25
|
2026-08-02 16:19:24 +02:00
|
|
|
ui.offset_transform_rotation = lerpf(ui.offset_transform_rotation, ui_rotation_target * PlayerConsts.UI_MOVEMENT_SENSITIVITY * 0.003, delta * PlayerConsts.UI_MOVEMENT_SPEED)
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
|
2026-07-30 01:44:27 +02:00
|
|
|
func footstep_sound():
|
2026-08-02 16:19:24 +02:00
|
|
|
var current_sin_pos = sin(t_bob * PlayerConsts.CAMERA_BOB_FREQUENCY)
|
2026-07-30 01:44:27 +02:00
|
|
|
|
|
|
|
|
if last_bob_y >= -.95 and current_sin_pos < -.95:
|
2026-08-09 03:24:28 +02:00
|
|
|
footstep.emit()
|
2026-07-30 01:44:27 +02:00
|
|
|
|
|
|
|
|
last_bob_y = current_sin_pos
|
2026-07-29 00:05:40 +02:00
|
|
|
|
2026-07-30 01:44:27 +02:00
|
|
|
func breathing_sound():
|
2026-07-29 13:52:14 +02:00
|
|
|
if _breathing:
|
2026-08-02 16:19:24 +02:00
|
|
|
var current_sin_pos = sin(t_breath * PlayerConsts.CAMERA_BOB_FREQUENCY)
|
2026-07-29 13:52:14 +02:00
|
|
|
|
|
|
|
|
if last_breath_y <= -.60 and current_sin_pos > -.60:
|
2026-08-09 03:24:28 +02:00
|
|
|
breath.emit(true)
|
2026-07-29 13:52:14 +02:00
|
|
|
|
|
|
|
|
if last_breath_y >= .60 and current_sin_pos < .60:
|
2026-08-09 03:24:28 +02:00
|
|
|
breath.emit(false)
|
2026-07-29 13:52:14 +02:00
|
|
|
|
|
|
|
|
last_breath_y = current_sin_pos
|
2026-07-30 01:44:27 +02:00
|
|
|
|
|
|
|
|
func get_breathing_bob_offset_pos() -> Vector3:
|
2026-08-02 16:19:24 +02:00
|
|
|
return Vector3(0, sin(t_breath * PlayerConsts.CAMERA_BOB_FREQUENCY) * PlayerConsts.CAMERA_BOB_AMPLITUDE + .75, 0)
|
2026-07-30 01:44:27 +02:00
|
|
|
|
|
|
|
|
func get_breathing_bob_offset_rot() -> Vector3:
|
2026-08-02 16:19:24 +02:00
|
|
|
return Vector3(sin(t_breath * PlayerConsts.CAMERA_BOB_FREQUENCY) * PlayerConsts.CAMERA_SIDEWAYS_BOB_AMPLITUDE, 0, 0)
|
2026-07-30 01:44:27 +02:00
|
|
|
|
|
|
|
|
func get_moving_bob_offset_pos() -> Vector3:
|
2026-08-02 16:19:24 +02:00
|
|
|
return Vector3(0, sin(t_bob * PlayerConsts.CAMERA_BOB_FREQUENCY) * PlayerConsts.CAMERA_BOB_AMPLITUDE, 0)
|
2026-07-30 01:44:27 +02:00
|
|
|
|
|
|
|
|
func get_moving_bob_offset_rot() -> Vector3:
|
2026-08-02 16:19:24 +02:00
|
|
|
return Vector3(0, 0, sin(t_bob * PlayerConsts.CAMERA_BOB_FREQUENCY * .5) * PlayerConsts.CAMERA_SIDEWAYS_BOB_AMPLITUDE)
|