added more dynamic camera and ui movements
yay, even more things to debug. dont worry, i got it i just need time
This commit is contained in:
parent
aecb2f5d89
commit
8b8f1d87c8
15 changed files with 152 additions and 233 deletions
32
scenes/player/cursor.tscn
Normal file
32
scenes/player/cursor.tscn
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
[gd_scene format=3 uid="uid://blh2biuk44qqj"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_3gngh"]
|
||||
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0]
|
||||
point_count = 1
|
||||
|
||||
[sub_resource type="Curve" id="Curve_fcnqv"]
|
||||
_data = [Vector2(0.6145833, 1), 0.0, 0.0, 0, 0]
|
||||
point_count = 1
|
||||
|
||||
[sub_resource type="Curve" id="Curve_7numd"]
|
||||
_data = [Vector2(0.6145833, 1), 0.0, 0.0, 0, 0]
|
||||
point_count = 1
|
||||
|
||||
[sub_resource type="CurveXYZTexture" id="CurveXYZTexture_nnoq1"]
|
||||
curve_x = SubResource("Curve_3gngh")
|
||||
curve_y = SubResource("Curve_fcnqv")
|
||||
curve_z = SubResource("Curve_7numd")
|
||||
|
||||
[node name="CursorContainer" type="AspectRatioContainer" unique_id=677513489]
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.49
|
||||
anchor_top = 0.49
|
||||
anchor_right = 0.51
|
||||
anchor_bottom = 0.51
|
||||
|
||||
[node name="Cursor" type="TextureRect" parent="." unique_id=382476320]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_transform_scale = Vector2(0.345, 0.345)
|
||||
texture = SubResource("CurveXYZTexture_nnoq1")
|
||||
expand_mode = 1
|
||||
|
|
@ -1,15 +1,12 @@
|
|||
class_name MovementComponent extends Node
|
||||
|
||||
@export var camera_pivot: Node3D
|
||||
@export var player_camera: Camera3D
|
||||
@export var player_hit_box: CollisionShape3D
|
||||
@export var player: Player
|
||||
|
||||
signal jumped
|
||||
signal landed(speed:float)
|
||||
signal running(is_running:bool)
|
||||
signal crouching(is_crouching:bool)
|
||||
signal walking(is_walking:bool)
|
||||
signal state_changed(state:String)
|
||||
|
||||
var mouse_motion: Vector2 = Vector2.ZERO
|
||||
var mouse_motion_delta: Vector2 = Vector2.ZERO
|
||||
|
|
@ -18,44 +15,7 @@ var runs: bool = false
|
|||
var walks: bool = false
|
||||
|
||||
var _player_spawned: bool = false
|
||||
|
||||
@onready var global_delta: float
|
||||
@onready var target_speed = PlayerConsts.SPEED
|
||||
|
||||
func jump():
|
||||
player.velocity.y = PlayerConsts.JUMP_VELOCITY
|
||||
jumped.emit()
|
||||
|
||||
func land(velocity: float):
|
||||
if _player_spawned:
|
||||
landed.emit(velocity)
|
||||
|
||||
func crouch(is_crouched:bool):
|
||||
if is_crouched:
|
||||
target_speed *= PlayerConsts.CROUCH_SPEED_MULTIPLIER
|
||||
|
||||
else:
|
||||
target_speed /= PlayerConsts.CROUCH_SPEED_MULTIPLIER
|
||||
|
||||
crouched = is_crouched
|
||||
crouching.emit(is_crouched)
|
||||
|
||||
func run(is_running:bool):
|
||||
if player.velocity.length() > 0:
|
||||
if is_running:
|
||||
target_speed *= PlayerConsts.SPRINT_MULTIPLIER
|
||||
else:
|
||||
target_speed /= PlayerConsts.SPRINT_MULTIPLIER
|
||||
|
||||
running.emit(is_running)
|
||||
|
||||
func walk(is_walking:bool):
|
||||
if is_walking:
|
||||
walks = true
|
||||
walking.emit(true)
|
||||
else:
|
||||
walks = false
|
||||
walking.emit(false)
|
||||
var _current_state: String = "idle"
|
||||
|
||||
func handle_joypad_movement():
|
||||
var controller_look_vector = Input.get_vector("look_left", "look_right", "look_up", "look_down") * 50
|
||||
|
|
@ -79,34 +39,66 @@ func _ready() -> void:
|
|||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
get_tree().create_timer(0.5).timeout.connect(func(): _player_spawned = true)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
global_delta = delta
|
||||
if Input.is_action_just_pressed("jump") and player.is_on_floor() and player.stamina_component.stamina > PlayerConsts.JUMP_STAMINA_COST:
|
||||
jump()
|
||||
|
||||
if crouched:
|
||||
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, .5, delta * 10)
|
||||
else:
|
||||
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, 2, delta * 10)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not Console.toggled or not UiManager.in_game_menu.visible:
|
||||
if Console.toggled or UiManager.in_game_menu.visible:
|
||||
player.velocity.x = lerpf(player.velocity.x, 0, delta * 10)
|
||||
player.velocity.z = lerpf(player.velocity.z, 0, delta * 10)
|
||||
player.move_and_slide()
|
||||
return
|
||||
|
||||
mouse_motion.y = clamp(mouse_motion.y, -1560, 1560)
|
||||
player.transform.basis = lerp(player.transform.basis, Basis.from_euler(Vector3(0, mouse_motion.x * -0.001 * PlayerConsts.LOOK_SENSITIVITY, 0)), delta * 30)
|
||||
player_camera.transform.basis = lerp(player_camera.transform.basis, Basis.from_euler(Vector3(mouse_motion.y * -0.001 * PlayerConsts.LOOK_SENSITIVITY, 0, 0)), delta * 30)
|
||||
|
||||
player.rotation.y = lerp_angle(player.rotation.y, mouse_motion.x * -0.001 * PlayerConsts.LOOK_SENSITIVITY, delta * 30)
|
||||
|
||||
var target_pitch = mouse_motion.y * -0.001 * PlayerConsts.LOOK_SENSITIVITY
|
||||
camera_pivot.rotation.x = lerp_angle(camera_pivot.rotation.x, target_pitch, delta * 30)
|
||||
|
||||
handle_joypad_movement()
|
||||
|
||||
var was_on_floor: bool = player.is_on_floor()
|
||||
var fall_velocity: float = player.velocity.y
|
||||
|
||||
if not player.is_on_floor():
|
||||
if not was_on_floor:
|
||||
player.velocity += player.get_gravity() * delta
|
||||
|
||||
if not UiManager.in_game_menu.visible and not Console.toggled:
|
||||
|
||||
var input_dir = Input.get_vector("left", "right", "forward", "backward")
|
||||
#var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
var target_speed = PlayerConsts.SPEED
|
||||
var new_state = "idle"
|
||||
var is_moving = input_dir != Vector2.ZERO
|
||||
|
||||
if Input.is_action_pressed("crouch"):
|
||||
target_speed *= PlayerConsts.CROUCH_SPEED_MULTIPLIER
|
||||
new_state = "crouch"
|
||||
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, 0.5, delta * 10)
|
||||
|
||||
else:
|
||||
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, 2, delta * 10)
|
||||
|
||||
if is_moving:
|
||||
if Input.is_action_pressed("sprint") and player.stamina_component.stamina > 0:
|
||||
target_speed *= PlayerConsts.SPRINT_MULTIPLIER
|
||||
new_state = "run"
|
||||
else:
|
||||
new_state = "walk"
|
||||
|
||||
if new_state != _current_state:
|
||||
_current_state = new_state
|
||||
state_changed.emit(new_state)
|
||||
|
||||
if Input.is_action_just_pressed("jump") and player.is_on_floor() and player.stamina_component.stamina > PlayerConsts.JUMP_STAMINA_COST:
|
||||
player.velocity.y += PlayerConsts.JUMP_VELOCITY
|
||||
jumped.emit()
|
||||
|
||||
var direction = (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
var accel_rate = 6.0 if is_moving else 9.0
|
||||
|
||||
if direction:
|
||||
player.velocity.x = lerpf(player.velocity.x, direction.x * target_speed, delta * accel_rate)
|
||||
player.velocity.z = lerpf(player.velocity.z, direction.z * target_speed, delta * accel_rate)
|
||||
else:
|
||||
player.velocity.x = lerpf(player.velocity.x, 0.0, delta * accel_rate)
|
||||
player.velocity.z = lerpf(player.velocity.z, 0.0, delta * accel_rate)
|
||||
|
||||
var lean_dir = -Input.get_axis("lean_left", "lean_right") * .1
|
||||
|
||||
if lean_dir:
|
||||
|
|
@ -115,55 +107,7 @@ func _physics_process(delta: float) -> void:
|
|||
else:
|
||||
camera_pivot.rotation.z = lerpf(camera_pivot.rotation.z, 0, delta*10)
|
||||
camera_pivot.position.x = lerpf(camera_pivot.position.x, 0, delta * 7)
|
||||
|
||||
var is_moving = input_dir != Vector2.ZERO
|
||||
|
||||
if Input.is_action_just_pressed("crouch"):
|
||||
crouch(true)
|
||||
elif Input.is_action_just_released("crouch"):
|
||||
crouch(false)
|
||||
|
||||
if Input.is_action_just_pressed("sprint") and player.stamina_component.stamina > 0:
|
||||
run(true)
|
||||
elif Input.is_action_just_released("sprint") or player.stamina_component.stamina == 0:
|
||||
run(false)
|
||||
|
||||
#apply motion
|
||||
var local_vel = player.transform.basis.inverse() * player.velocity
|
||||
var target_local_vel = Vector3(player_camera.transform.basis * Vector3(input_dir.x, 0, input_dir.y)) * target_speed
|
||||
var accel_rate = 6.0 if is_moving else 9.0
|
||||
|
||||
local_vel.x = lerpf(local_vel.x, target_local_vel.x, delta * accel_rate)
|
||||
local_vel.z = lerpf(local_vel.z, target_local_vel.z, delta * accel_rate)
|
||||
|
||||
var global_horizontal = player.transform.basis * local_vel
|
||||
player.velocity.x = global_horizontal.x
|
||||
player.velocity.z = global_horizontal.z
|
||||
|
||||
if (Input.is_action_just_pressed("forward") \
|
||||
or Input.is_action_just_pressed("backward") \
|
||||
or Input.is_action_just_pressed("left") \
|
||||
or Input.is_action_just_pressed("right")
|
||||
) and not runs and not crouched and not walks:
|
||||
walk(true)
|
||||
elif walks and not (Input.is_action_pressed("forward") \
|
||||
or Input.is_action_pressed("backward") \
|
||||
or Input.is_action_pressed("left") \
|
||||
or Input.is_action_pressed("right")):
|
||||
walk(false)
|
||||
|
||||
else:
|
||||
player.velocity.x = lerpf(player.velocity.x, 0, delta * 10)
|
||||
player.velocity.z = lerpf(player.velocity.z, 0, delta * 10)
|
||||
|
||||
player.move_and_slide()
|
||||
|
||||
if not was_on_floor and player.is_on_floor():
|
||||
land(fall_velocity)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta: float) -> void:
|
||||
#_mouse_motion.y = clamp(_mouse_motion.y, -1560, 1560)
|
||||
#player.transform.basis = Basis.from_euler(Vector3(0, _mouse_motion.x * -0.001 * LOOK_SENSITIVITY, 0))
|
||||
#player.transform.basis = lerp(player_camera.transform.basis, Basis.from_euler(Vector3(_mouse_motion.y * -0.001 * LOOK_SENSITIVITY, 0, 0)), delta * 10)
|
||||
#
|
||||
if not was_on_floor and player.is_on_floor() and _player_spawned:
|
||||
landed.emit(fall_velocity)
|
||||
|
|
|
|||
|
|
@ -23,30 +23,18 @@ func _ready() -> void:
|
|||
inventory_component.add_item.connect(ui.add_item)
|
||||
inventory_component.remove_item.connect(ui.remove_item)
|
||||
|
||||
SignalSniffer.watch(inventory_component)
|
||||
|
||||
procedural_animator.breath.connect(sound_controller.play_breath_sound)
|
||||
procedural_animator.footstep.connect(sound_controller.play_footstep_sound)
|
||||
|
||||
SignalSniffer.watch(procedural_animator)
|
||||
|
||||
input_controller.stamina_reset.connect(stamina_component.restart_timer)
|
||||
input_controller.toggle_flashlight.connect(flashlight_component.toggle_flashlight)
|
||||
input_controller.toggle_flashlight.connect(sound_controller.play_flashlight_sound)
|
||||
|
||||
SignalSniffer.watch(input_controller)
|
||||
|
||||
stamina_component.stamina_changed.connect(ui.set_stamina)
|
||||
|
||||
SignalSniffer.watch(stamina_component)
|
||||
|
||||
movement_component.jumped.connect(stamina_component.jump)
|
||||
movement_component.jumped.connect(sound_controller.play_jump_sound)
|
||||
movement_component.jumped.connect(player_state.jump)
|
||||
movement_component.landed.connect(sound_controller.play_land_sound )
|
||||
movement_component.walking.connect(player_state.is_walking)
|
||||
movement_component.running.connect(player_state.is_running)
|
||||
movement_component.running.connect(stamina_component.run)
|
||||
movement_component.crouching.connect(player_state.is_crouched)
|
||||
movement_component.landed.connect(sound_controller.play_land_sound)
|
||||
|
||||
SignalSniffer.watch(movement_component)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
[ext_resource type="Script" uid="uid://dntoi54g4hqce" path="res://scenes/player/flashlight_component.gd" id="11_myrg7"]
|
||||
[ext_resource type="Script" uid="uid://cdfis3askl3gb" path="res://scenes/player/stamina_component.gd" id="12_kvlxm"]
|
||||
[ext_resource type="PackedScene" uid="uid://c02fkimxlbrje" path="res://scenes/player/prompt.tscn" id="13_ugbui"]
|
||||
[ext_resource type="PackedScene" uid="uid://blh2biuk44qqj" path="res://scenes/player/cursor.tscn" id="14_fcs02"]
|
||||
[ext_resource type="AudioStream" uid="uid://0q6nhlhgnxu2" path="res://assets/sounds/whitenoise.mp3" id="14_ugbui"]
|
||||
[ext_resource type="Script" uid="uid://dr2lwciaohf6f" path="res://scenes/player/movement_component.gd" id="60_s3g0c"]
|
||||
[ext_resource type="Script" uid="uid://cjk6a0da11ge6" path="res://scenes/player/procedural_animator.gd" id="61_hggc2"]
|
||||
|
|
@ -37,11 +38,10 @@ player_state = NodePath("Components/PlayerState")
|
|||
|
||||
[node name="Components" type="Node" parent="." unique_id=1652812621]
|
||||
|
||||
[node name="MovementComponent" type="Node" parent="Components" unique_id=1821617467 node_paths=PackedStringArray("camera_pivot", "player_camera", "player_hit_box", "player")]
|
||||
[node name="MovementComponent" type="Node" parent="Components" unique_id=1821617467 node_paths=PackedStringArray("camera_pivot", "player_hit_box", "player")]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("60_s3g0c")
|
||||
camera_pivot = NodePath("../../CameraPivot")
|
||||
player_camera = NodePath("../../CameraPivot/PlayerCamera")
|
||||
player_hit_box = NodePath("../../PlayerHitBox")
|
||||
player = NodePath("../..")
|
||||
|
||||
|
|
@ -169,8 +169,11 @@ current = true
|
|||
unique_name_in_owner = true
|
||||
visible = false
|
||||
|
||||
[node name="PlayerUi" parent="." unique_id=454848358 instance=ExtResource("2_rkbax")]
|
||||
[node name="PlayerUi" parent="." unique_id=454848358 node_paths=PackedStringArray("cursor") instance=ExtResource("2_rkbax")]
|
||||
unique_name_in_owner = true
|
||||
cursor = NodePath("../AspectRatioContainer2")
|
||||
|
||||
[node name="AspectRatioContainer2" parent="." unique_id=677513489 instance=ExtResource("14_fcs02")]
|
||||
|
||||
[node name="StaminaReset" type="Timer" parent="." unique_id=1815815085]
|
||||
unique_name_in_owner = true
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ class_name PlayerUI extends Control
|
|||
|
||||
@onready var inventory_slots_panels: Array[TextureRect] = [%InvSlot1, %InvSlot2, %InvSlot3, %InvSlot4, %InvSlot5]
|
||||
|
||||
@export var cursor: AspectRatioContainer
|
||||
|
||||
var inventory_size: int = 2
|
||||
|
||||
## returns true if successful
|
||||
|
|
@ -39,12 +41,16 @@ const UNSELECTED_COLOR = 0x3d3d3d78
|
|||
var selected_stylebox: StyleBoxFlat = StyleBoxFlat.new()
|
||||
var unselected_stylebox: StyleBoxFlat = StyleBoxFlat.new()
|
||||
|
||||
func toggle_cursor():
|
||||
cursor.visible = !cursor.visible
|
||||
|
||||
func _ready():
|
||||
selected_stylebox.bg_color = SELECTED_COLOR
|
||||
unselected_stylebox.bg_color = UNSELECTED_COLOR
|
||||
Console.add_inventory.connect(add_inventory_slot_console)
|
||||
Console.remove_inventory.connect(remove_inventory_slot_console)
|
||||
pivot_offset = get_viewport_rect().size / 2
|
||||
visibility_changed.connect(toggle_cursor)
|
||||
|
||||
func select_item(index):
|
||||
if index >= 0 and index < inventory_size:
|
||||
|
|
|
|||
|
|
@ -8,23 +8,6 @@ bg_color = Color(0.23921569, 0.23921569, 0.23921569, 0.47058824)
|
|||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_b5l5s"]
|
||||
bg_color = Color(0.6, 0.6, 0.6, 0)
|
||||
|
||||
[sub_resource type="Curve" id="Curve_3gngh"]
|
||||
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0]
|
||||
point_count = 1
|
||||
|
||||
[sub_resource type="Curve" id="Curve_fcnqv"]
|
||||
_data = [Vector2(0.6145833, 1), 0.0, 0.0, 0, 0]
|
||||
point_count = 1
|
||||
|
||||
[sub_resource type="Curve" id="Curve_7numd"]
|
||||
_data = [Vector2(0.6145833, 1), 0.0, 0.0, 0, 0]
|
||||
point_count = 1
|
||||
|
||||
[sub_resource type="CurveXYZTexture" id="CurveXYZTexture_32d7b"]
|
||||
curve_x = SubResource("Curve_3gngh")
|
||||
curve_y = SubResource("Curve_fcnqv")
|
||||
curve_z = SubResource("Curve_7numd")
|
||||
|
||||
[node name="PlayerUi" type="Control" unique_id=454848358]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
|
|
@ -199,20 +182,3 @@ custom_minimum_size = Vector2(0, 50)
|
|||
layout_mode = 2
|
||||
offset_transform_enabled = true
|
||||
show_percentage = false
|
||||
|
||||
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="." unique_id=1864185410]
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.49
|
||||
anchor_top = 0.49
|
||||
anchor_right = 0.51
|
||||
anchor_bottom = 0.51
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Cursor" type="TextureRect" parent="AspectRatioContainer" unique_id=417293523]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
offset_transform_scale = Vector2(0.345, 0.345)
|
||||
texture = SubResource("CurveXYZTexture_32d7b")
|
||||
expand_mode = 1
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class_name ProceduralAnimator extends Node
|
||||
|
||||
@export var player: Player
|
||||
@export var player: CharacterBody3D # Changed to CharacterBody3D for safety
|
||||
@export var camera: Camera3D
|
||||
@export var ui: Control
|
||||
@export var movement: Node
|
||||
|
|
@ -13,103 +13,92 @@ var t_breath: float = 0.0
|
|||
var last_breath_y: float = 0.0
|
||||
var target_rotation: Vector3 = Vector3.ZERO
|
||||
|
||||
var _last_camera_global_position: Vector3 = Vector3.ZERO
|
||||
var _smoothed_velocity: Vector3 = Vector3.ZERO
|
||||
var _breathing: bool = true
|
||||
var _last_camera_global_position: Vector3 = Vector3.ZERO
|
||||
|
||||
#signals for emitting sounds
|
||||
signal footstep
|
||||
signal breath(breathe_in:bool)
|
||||
|
||||
func _ready() -> void:
|
||||
_last_camera_global_position = camera.global_position
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
camera.rotation += target_rotation
|
||||
signal breath(breathe_in: bool)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not UiManager.in_game_menu.visible:
|
||||
do(delta)
|
||||
if player.is_on_floor():
|
||||
_breathing = true
|
||||
else:
|
||||
_breathing = false
|
||||
delta = min(delta, 0.05)
|
||||
|
||||
_breathing = player.is_on_floor()
|
||||
do(delta)
|
||||
footstep_sound()
|
||||
breathing_sound()
|
||||
|
||||
func do(delta):
|
||||
ui.offset_transform_scale *= PlayerConsts.UI_SCALE
|
||||
ui_movement_handling(delta)
|
||||
func do(delta: float):
|
||||
_smoothed_velocity = _smoothed_velocity.lerp(player.velocity, 1.0 - exp(-15.0 * delta))
|
||||
|
||||
var horizontal_speed = Vector3(player.velocity.x, player.velocity.y, player.velocity.z).length()
|
||||
var cam_local_vel = camera.global_transform.basis.inverse() * _smoothed_velocity
|
||||
|
||||
ui_movement_handling(delta, cam_local_vel)
|
||||
|
||||
var horizontal_speed = player.velocity.length()
|
||||
|
||||
if _breathing:
|
||||
t_breath += delta * (100 / (40 + player.stamina_component.stamina))
|
||||
t_breath += delta * (100.0 / (40.0 + player.stamina_component.stamina))
|
||||
|
||||
var target_pos = get_breathing_bob_offset_pos()
|
||||
var target_rot = get_breathing_bob_offset_rot()
|
||||
|
||||
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)
|
||||
t_bob += delta * (horizontal_speed + (int(Input.is_action_pressed("crouch")) * 3.0))
|
||||
|
||||
target_pos += get_moving_bob_offset_pos()
|
||||
target_rot += get_moving_bob_offset_rot()
|
||||
|
||||
camera.transform.origin = camera.transform.origin.lerp(target_pos, delta * 10)
|
||||
camera.position = camera.position.lerp(target_pos, delta * 10.0)
|
||||
|
||||
var final_pitch = target_rot.x
|
||||
var final_roll = target_rot.z
|
||||
var final_pitch = target_rot.x + (cam_local_vel.z * 0.005 - cam_local_vel.y * 0.01)
|
||||
var final_roll = target_rot.z - (cam_local_vel.x * 0.005)
|
||||
|
||||
target_rotation = Vector3(final_pitch, 0, final_roll)
|
||||
camera.rotation = Vector3(final_pitch, 0, final_roll)
|
||||
|
||||
func ui_movement_handling(delta: float):
|
||||
func ui_movement_handling(delta: float, cam_local_vel: Vector3):
|
||||
var mouse_offset = -movement.mouse_motion_delta * PlayerConsts.UI_MOVEMENT_SENSITIVITY
|
||||
|
||||
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
|
||||
|
||||
# We use the safe velocity calculated in do() instead of manual positions
|
||||
var inertia_offset = Vector2(
|
||||
-cam_local_vel.x,
|
||||
cam_local_vel.y - (cam_local_vel.z * 0.25)
|
||||
) * PlayerConsts.CAMERA_VELOCITY_MULTIPLIER
|
||||
|
||||
var target_offset = mouse_offset + inertia_offset
|
||||
var camera_global_velocity = (camera.global_position - _last_camera_global_position) / delta
|
||||
|
||||
var bob_offset: Vector2 = Vector2(-camera_global_velocity.x, camera_global_velocity.y)
|
||||
|
||||
var target_offset = mouse_offset + inertia_offset + bob_offset * 5
|
||||
var weighted_lerp = 1.0 - exp(-PlayerConsts.UI_MOVEMENT_SPEED * delta)
|
||||
|
||||
ui.position = ui.position.lerp(ui_base_position + target_offset, weighted_lerp)
|
||||
|
||||
_last_camera_global_position = current_camera_global_position
|
||||
|
||||
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)
|
||||
var ui_scaling_target = Vector2(-cam_local_vel.z * PlayerConsts.UI_MOVEMENT_SENSITIVITY * .002 + 1.0, -cam_local_vel.z * PlayerConsts.UI_MOVEMENT_SENSITIVITY * .002 + 1.0)
|
||||
ui.offset_transform_scale = ui.offset_transform_scale.lerp(ui_scaling_target, weighted_lerp)
|
||||
|
||||
var ui_rotation_target = -inertia_offset.x - mouse_offset.x * 0.25
|
||||
ui.offset_transform_rotation = lerpf(ui.offset_transform_rotation, ui_rotation_target * PlayerConsts.UI_MOVEMENT_SENSITIVITY * 0.003, weighted_lerp)
|
||||
|
||||
_last_camera_global_position = camera.global_position
|
||||
|
||||
func footstep_sound():
|
||||
var current_sin_pos = sin(t_bob * PlayerConsts.CAMERA_BOB_FREQUENCY)
|
||||
|
||||
if last_bob_y >= -.95 and current_sin_pos < -.95:
|
||||
if last_bob_y >= -0.95 and current_sin_pos < -0.95:
|
||||
footstep.emit()
|
||||
|
||||
last_bob_y = current_sin_pos
|
||||
|
||||
func breathing_sound():
|
||||
if _breathing:
|
||||
var current_sin_pos = sin(t_breath * PlayerConsts.CAMERA_BOB_FREQUENCY)
|
||||
|
||||
if last_breath_y <= -.60 and current_sin_pos > -.60:
|
||||
if last_breath_y <= -0.60 and current_sin_pos > -0.60:
|
||||
breath.emit(true)
|
||||
|
||||
if last_breath_y >= .60 and current_sin_pos < .60:
|
||||
if last_breath_y >= 0.60 and current_sin_pos < 0.60:
|
||||
breath.emit(false)
|
||||
|
||||
last_breath_y = current_sin_pos
|
||||
|
||||
func get_breathing_bob_offset_pos() -> Vector3:
|
||||
return Vector3(0, sin(t_breath * PlayerConsts.CAMERA_BOB_FREQUENCY) * PlayerConsts.CAMERA_BOB_AMPLITUDE + .75, 0)
|
||||
return Vector3(0, sin(t_breath * PlayerConsts.CAMERA_BOB_FREQUENCY) * PlayerConsts.CAMERA_BOB_AMPLITUDE + 0.75, 0)
|
||||
|
||||
func get_breathing_bob_offset_rot() -> Vector3:
|
||||
return Vector3(sin(t_breath * PlayerConsts.CAMERA_BOB_FREQUENCY) * PlayerConsts.CAMERA_SIDEWAYS_BOB_AMPLITUDE, 0, 0)
|
||||
|
|
@ -118,4 +107,4 @@ func get_moving_bob_offset_pos() -> Vector3:
|
|||
return Vector3(0, sin(t_bob * PlayerConsts.CAMERA_BOB_FREQUENCY) * PlayerConsts.CAMERA_BOB_AMPLITUDE, 0)
|
||||
|
||||
func get_moving_bob_offset_rot() -> Vector3:
|
||||
return Vector3(0, 0, sin(t_bob * PlayerConsts.CAMERA_BOB_FREQUENCY * .5) * PlayerConsts.CAMERA_SIDEWAYS_BOB_AMPLITUDE)
|
||||
return Vector3(0, 0, sin(t_bob * PlayerConsts.CAMERA_BOB_FREQUENCY * 0.5) * PlayerConsts.CAMERA_SIDEWAYS_BOB_AMPLITUDE)
|
||||
|
|
|
|||
|
|
@ -138,7 +138,6 @@ func play_breath_sound(breathe_in:bool = true):
|
|||
if breathe_in:
|
||||
play_sound = _current_breath_in_sound
|
||||
while play_sound == _current_breath_in_sound:
|
||||
print("breathe in")
|
||||
match player.player_state.breathing_mode:
|
||||
player.player_state.breath.calm:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_IN_CALM)
|
||||
|
|
@ -177,7 +176,6 @@ func play_flashlight_sound():
|
|||
var play_sound = Sounds.get_random_sound(Sounds.FLASHLIGHT_CLICK_SOUNDS)
|
||||
|
||||
while play_sound == _current_flashlight_sound:
|
||||
print("flashlight sound")
|
||||
play_sound = Sounds.get_random_sound(Sounds.FLASHLIGHT_CLICK_SOUNDS)
|
||||
|
||||
_current_flashlight_sound = play_sound
|
||||
|
|
@ -194,10 +192,8 @@ func play_land_sound(velocity: float):
|
|||
|
||||
volume = velocity
|
||||
while sound_to_play_foot == _current_jump_land_sound:
|
||||
print("land foot")
|
||||
sound_to_play_foot = Sounds.get_random_sound(Sounds.JUMP_LANDING_SOUNDS)
|
||||
while sound_to_play_breath == _current_jump_land_breath_sound:
|
||||
print("land breath")
|
||||
sound_to_play_breath = Sounds.get_random_sound(Sounds.JUMP_LANDING_BREATH_SOUNDS)
|
||||
|
||||
_current_jump_land_sound = sound_to_play_foot
|
||||
|
|
@ -212,10 +208,8 @@ func play_jump_sound():
|
|||
var volume:float = 1.0
|
||||
|
||||
while sound_to_play_foot == _current_jump_start_sound:
|
||||
print("jump foot")
|
||||
sound_to_play_foot = Sounds.get_random_sound(Sounds.JUMP_STARTING_SOUNDS)
|
||||
while sound_to_play_breath == _current_jump_start_breath_sound:
|
||||
print("jump breath")
|
||||
sound_to_play_breath = Sounds.get_random_sound(Sounds.JUMP_STARTING_BREATH_SOUNDS)
|
||||
|
||||
_current_jump_start_sound = sound_to_play_foot
|
||||
|
|
@ -229,19 +223,16 @@ func play_footstep_sound():
|
|||
if player.player_state.walking:
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.NORMAL_FOOTSTEP_SOUNDS)
|
||||
while sound_to_play == _current_footstep_sound:
|
||||
print("walk")
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.NORMAL_FOOTSTEP_SOUNDS)
|
||||
elif player.player_state.running:
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.HEAVY_FOOTSTEP_SOUNDS)
|
||||
while sound_to_play == _current_footstep_sound:
|
||||
print("run")
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.HEAVY_FOOTSTEP_SOUNDS)
|
||||
if randf_range(1, 100) > 100 - PlayerConsts.SHUFFLE_CHANCE:
|
||||
play_stream_on_player(is_right_leg.call().get_child(0), Sounds.get_random_sound(Sounds.SHUFFLE_FOOTSTEP_SOUNDS))
|
||||
elif player.player_state.crouching:
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.LIGHT_FOOTSTEP_SOUNDS)
|
||||
while sound_to_play == _current_footstep_sound:
|
||||
print("crouch")
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.LIGHT_FOOTSTEP_SOUNDS)
|
||||
|
||||
_current_footstep_sound = sound_to_play
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene format=3 uid="uid://c57oxgn18vrdv"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bbffh34pb664i" path="res://scenes/player/debug_menu.gd" id="1_a4365"]
|
||||
[ext_resource type="Script" uid="uid://bbffh34pb664i" path="res://scenes/ui/debug_menu/debug_menu.gd" id="1_a4365"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_60a4j"]
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene format=3 uid="uid://046i0offx3w8"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://br8pa51piwxuy" path="res://scenes/ui/loading_screen.gd" id="1_rqdcv"]
|
||||
[ext_resource type="Script" uid="uid://br8pa51piwxuy" path="res://scenes/ui/loading_screen/loading_screen.gd" id="1_rqdcv"]
|
||||
|
||||
[node name="LoadingScreen" type="CanvasLayer" unique_id=721141233]
|
||||
script = ExtResource("1_rqdcv")
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[ext_resource type="Script" uid="uid://33wtl3qa013n" path="res://scenes/ui/ui_manager.gd" id="1_b2463"]
|
||||
[ext_resource type="PackedScene" uid="uid://y5f3db7clptv" path="res://scenes/player/in_game_menu.tscn" id="2_js4l8"]
|
||||
[ext_resource type="PackedScene" uid="uid://c57oxgn18vrdv" path="res://scenes/player/debug_menu.tscn" id="3_61ox6"]
|
||||
[ext_resource type="PackedScene" uid="uid://c57oxgn18vrdv" path="res://scenes/ui/debug_menu/debug_menu.tscn" id="3_61ox6"]
|
||||
|
||||
[node name="UIManager" type="Control" unique_id=585290585]
|
||||
layout_mode = 3
|
||||
|
|
|
|||
Loading…
Reference in a new issue