110 lines
4.9 KiB
GDScript3
110 lines
4.9 KiB
GDScript3
|
|
extends CharacterBody3D
|
||
|
|
class_name PlayerCharacter
|
||
|
|
|
||
|
|
##TODO make it so that you can easily tweak settings from here, cascading to the components
|
||
|
|
|
||
|
|
@export_category("Movement")
|
||
|
|
@export var SPEED = 5.0 ##base walking speed
|
||
|
|
@export var SPRINT_MULTIPLIER = 1.5 ##how much faster should you move, when sprinting
|
||
|
|
@export var SPRINT_STAMINA_COST = 10.0 ##how much stamina should be consumed each frame while sprinting (delta * SPRINT_STAMINA_COST)
|
||
|
|
@export var CROUCH_SPEED_MULTIPLIER = .5 ##how much slower you should be going while crouching
|
||
|
|
|
||
|
|
@export_category("Jump")
|
||
|
|
@export var JUMP_VELOCITY = 4.5 ##how high you can jump
|
||
|
|
@export var JUMP_STAMINA_COST = 10 ##how much stamina each jump consumes
|
||
|
|
|
||
|
|
@export_category("Camera")
|
||
|
|
@export var LOOK_SENSITIVITY = 1.0 ##camera sensitivity
|
||
|
|
@export var CAMERA_VELOCITY_MULTIPLIER = 1.5 ##how heavy should the UI movement feel
|
||
|
|
@export var CAMERA_BOB_FREQUENCY = 2.4 ##how quick the camera bobs whilst moving
|
||
|
|
@export var CAMERA_BOB_AMPLITUDE = 0.08 ##how hard the camera bobs whilst moving
|
||
|
|
@export var CAMERA_BOB_MULTIPLIER = 200.0 ##how much the ui reacts to head bobbing
|
||
|
|
@export var CAMERA_SIDEWAYS_BOB_AMPLITUDE = 0.003 ## how many degrees does the camera bob sideways
|
||
|
|
|
||
|
|
@export_category("UI")
|
||
|
|
@export var UI_SCALE: float = 1 ##rational scale of the ui
|
||
|
|
@export var UI_MOVEMENT_SENSITIVITY = 0.5 ##how much the UI moves when you move the camera
|
||
|
|
@export var UI_MOVEMENT_SPEED = 15.0 ##how fast the UI moves when you move the camera
|
||
|
|
@export var UI_MOVEMENT_VELOCITY_MULTIPLIER = 2.0 ##how much the ui leans when walking or strafing
|
||
|
|
|
||
|
|
@export_category("Inventory")
|
||
|
|
@export var INVENTORY_MAX = 3 ##max number of items that can be in the player's inventory
|
||
|
|
@export var INVENTORY_ITEMS: Array = [] ##the items in the player's inventory
|
||
|
|
|
||
|
|
@export_category("Audio")
|
||
|
|
@export var AUDIO_LOUDNESS: float = 100.0
|
||
|
|
@export var NORMAL_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##normal footsteps -- walking
|
||
|
|
@export var HEAVY_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##heavy footsteps -- running
|
||
|
|
@export var LIGHT_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##light footsteps -- crouching
|
||
|
|
@export var SHUFFLE_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##shuffling -- random chance of playing while running
|
||
|
|
@export var FLASHLIGHT_CLICK_SOUNDS: Array[AudioStreamWAV] ##flashlight click
|
||
|
|
@export var SHUFFLE_CHANCE: float = 20 ##percentage of chance for a shuffle noise to be played whilst running
|
||
|
|
|
||
|
|
@export_category("Grabbing")
|
||
|
|
@export var GRAB_POWER: float = 15.0 ##how fast the grabbed object snaps to the hold position
|
||
|
|
@export var GRAB_ROTATION_POWER: float = 15.0 ##how fast the object rotates towards the player
|
||
|
|
@export var GRAB_PANEL: PackedScene ##panel that goes over the grabbable object to show its grabbable
|
||
|
|
|
||
|
|
@export_category("Player Physics")
|
||
|
|
@export_flags_3d_physics var PLAYER_COLLISION_MASK: int = 16
|
||
|
|
|
||
|
|
@onready var camera = $CameraPivot/PlayerCamera
|
||
|
|
@onready var camera_pivot = $CameraPivot
|
||
|
|
@onready var ui = $PlayerUi
|
||
|
|
@onready var ui_base_position = ui.position
|
||
|
|
@onready var in_game_menu = $InGameMenu
|
||
|
|
@onready var left_foot_sound_player = $SoundEmitters/LeftFoot
|
||
|
|
@onready var left_foot_texture_sound_player = $SoundEmitters/LeftFoot/LeftFootTexture
|
||
|
|
@onready var right_foot_sound_player = $SoundEmitters/RightFoot
|
||
|
|
@onready var right_foot_texture_sound_player = $SoundEmitters/RightFoot/RightFootTexture
|
||
|
|
@onready var flashlight_sound_player = $SoundEmitters/FlashlightSound
|
||
|
|
@onready var cursor_raycast = $CameraPivot/PlayerCamera/CursorRaycast
|
||
|
|
@onready var hold_position = $CameraPivot/PlayerCamera/HoldPosition
|
||
|
|
@onready var popup_panels = $PopupPanels
|
||
|
|
|
||
|
|
var walking: bool = false
|
||
|
|
var running: bool = false
|
||
|
|
var crouching: bool = false
|
||
|
|
var in_menu: bool = false
|
||
|
|
var stamina: float = 100.0
|
||
|
|
var stamina_recharge_on: bool = false
|
||
|
|
var selected_item: int = 0
|
||
|
|
var t_bob: float = 0
|
||
|
|
var last_bob_y: float = 0.0
|
||
|
|
var held_object: RigidBody3D = null
|
||
|
|
|
||
|
|
var _mouse_motion: Vector2 = Vector2.ZERO
|
||
|
|
var _mouse_motion_delta: Vector2 = Vector2.ZERO
|
||
|
|
var _last_camera_global_position: Vector3 = Vector3.ZERO
|
||
|
|
var _current_leg_is_right: bool = false ##if true: current leg is the right leg
|
||
|
|
var _current_footstep_sound: AudioStreamWAV = null
|
||
|
|
var _current_flashlight_sound: AudioStreamWAV = null
|
||
|
|
var _camera_original_position: Vector3 = Vector3(0,.75,0)
|
||
|
|
|
||
|
|
# components
|
||
|
|
@onready var procedural_camera_mover: Node = %ProceduralCameraMover
|
||
|
|
@onready var sound_controller: Node = %SoundController
|
||
|
|
@onready var ui_handler: Node = %UiHandler
|
||
|
|
@onready var input_controller: Node = %InputController
|
||
|
|
@onready var player_state: Node = %PlayerState
|
||
|
|
@onready var player_properties: Node = %PlayerProperties
|
||
|
|
|
||
|
|
func _process(delta: float) -> void:
|
||
|
|
if Input.is_action_just_pressed("next_item"):
|
||
|
|
ui_handler.next_item()
|
||
|
|
|
||
|
|
if Input.is_action_just_pressed("prev_item"):
|
||
|
|
ui_handler.prev_item()
|
||
|
|
|
||
|
|
if Input.is_action_just_pressed("select_item_1"):
|
||
|
|
ui_handler.select_item(0)
|
||
|
|
|
||
|
|
if Input.is_action_just_pressed("select_item_2"):
|
||
|
|
ui_handler.select_item(1)
|
||
|
|
|
||
|
|
if Input.is_action_just_pressed("select_item_3"):
|
||
|
|
ui_handler.select_item(2)
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
ui_handler.select_item(0)
|