extends CharacterBody3D class_name Player ## The base class for any input-driven character ## ## The Player class drives the associated Model with the input from the InputHandler, ## which drives the Visual. Each submodule can be swapped out for easy customization. ## The CameraHandler is to allow input to be made relative to the current camera's position ## ## Human-readable name for UI display @export var display_name := "" ## Ceiling for hit points @export var max_hit_points: float = 100.0 ## Ceiling for stamina points @export var max_stamina_points: float = 100.0 ## Ceiling for energy points @export var max_energy_points: float = 100.0 ## Rate of stamina regeneration @export var stamina_regain_per_sec: float = 80.0 ## Remaps absolute input relative to current camera. ## Bad idea for robots, good idea for player control! [br] ## [br] ## TODO: Probably should be all managed by the InputHandler! @export var input_is_relative_to_camera: bool = false ## Current state name of the PlayerModel state machine. For debugging. var state_name := "" ## How long the player has been idle. Populated by the Idle state. var idle_time := 0.00 ## Points to the last meaningful movement of the Player. var last_movement_vector: Vector3 ## For debugging. Records the floor normal. var floor_normal := Vector3.ZERO ## For debugging. How much the immediate slope influences velocity. var ground_slope_input := 0.0 @export_category("Instance") ## Current hit points @export var hit_points: float = 100.0 ## Current stamina points @export var stamina_points: float = 100.0 ## Current energy points @export var energy_points: float = 0.0 # onready @onready var input: InputHandler = $Input @onready var model: CharacterModel = $Model @onready var visual: CharacterVisual = $Model/Visual @onready var cameraHandler: CameraHandler = $CameraHandler @onready var collision: CollisionShape3D = $Collision func _ready() -> void: visual.assign_skeleton(model.skeleton) last_movement_vector = Vector3.BACK.rotated(Vector3.UP, rotation.y) func _physics_process(delta: float) -> void: var input_pkt := input.get_player_input() if input_is_relative_to_camera: cameraHandler.update(input_pkt, delta) cameraHandler.camera_distance = PlayerVariables.camera_distance + velocity.length() / 4 input_pkt.player_movement_direction = cameraHandler.get_xz_direction_relative_to_camera( input_pkt.player_movement_direction ) model.update(input_pkt, delta) input_pkt.queue_free()