]> purplebirdman git - frog-ninja.git/blob - asset/character/player/player.gd
86660362c6ce609274d921af53f8fa9eb62eb939
[frog-ninja.git] / asset / character / player / player.gd
1 extends CharacterBody3D
2 class_name Player
3 ## The base class for any input-driven character
4 ##
5 ## The Player class drives the associated Model with the input from the InputHandler,
6 ## which drives the Visual. Each submodule can be swapped out for easy customization.
7 ## The CameraHandler is to allow input to be made relative to the current camera's position
8 ##
9
10
11 ## Human-readable name for UI display
12 @export var display_name := ""
13
14 ## Ceiling for hit points
15 @export var max_hit_points: float = 100.0
16
17 ## Ceiling for stamina points
18 @export var max_stamina_points: float = 100.0
19
20 ## Ceiling for energy points
21 @export var max_energy_points: float = 100.0
22
23 ## Rate of stamina regeneration
24 @export var stamina_regain_per_sec: float = 80.0
25
26 ## Remaps absolute input relative to current camera.
27 ## Bad idea for robots, good idea for player control! [br]
28 ## [br]
29 ## TODO: Probably should be all managed by the InputHandler!
30 @export var input_is_relative_to_camera: bool = false
31
32
33 ## Current state name of the PlayerModel state machine. For debugging.
34 var state_name := ""
35
36 ## How long the player has been idle. Populated by the Idle state.
37 var idle_time := 0.00
38
39 ## Points to the last meaningful movement of the Player.
40 var last_movement_vector: Vector3
41
42 ## For debugging. Records the floor normal.
43 var floor_normal := Vector3.ZERO
44
45 ## For debugging. How much the immediate slope influences velocity.
46 var ground_slope_input := 0.0
47
48
49 @export_category("Instance")
50
51 ## Current hit points
52 @export var hit_points: float = 100.0
53
54 ## Current stamina points
55 @export var stamina_points: float = 100.0
56
57 ## Current energy points
58 @export var energy_points: float = 0.0
59
60 # onready
61 @onready var input: InputHandler = $Input
62 @onready var model: CharacterModel = $Model
63 @onready var visual: CharacterVisual = $Model/Visual
64 @onready var cameraHandler: CameraHandler = $CameraHandler
65 @onready var collision: CollisionShape3D = $Collision
66
67
68 func _ready() -> void:
69         visual.assign_skeleton(model.skeleton)
70         last_movement_vector = Vector3.BACK.rotated(Vector3.UP, rotation.y)
71
72
73 func _physics_process(delta: float) -> void:
74         var input_pkt := input.get_player_input()
75         
76         if input_is_relative_to_camera:
77                 cameraHandler.update(input_pkt, delta)
78                 cameraHandler.camera_distance = PlayerVariables.camera_distance + velocity.length() / 4
79                 input_pkt.player_movement_direction = cameraHandler.get_xz_direction_relative_to_camera(
80                         input_pkt.player_movement_direction
81                         )
82
83         model.update(input_pkt, delta)
84         
85         input_pkt.queue_free()