bazar_alea/client/player/PlayerGameplayComponent.gd

53 lines
2 KiB
GDScript3
Raw Normal View History

2023-11-14 21:41:08 +00:00
extends CharacterMovementComponent
class_name PlayerGameplayComponent
@export_group("Stamina System", "stamina_")
@export var stamina_use: bool = false
2023-11-20 22:18:02 +00:00
@export var stamina_energy_consumption: float = 15.0 #per second
2023-11-14 21:41:08 +00:00
@export var stamina_attribute: GameAttribute
@export var networking : PlayerNetworkingComponent
@export var targeting_component : TargetingComponent
func _ready():
targeting_component.connect("detected", func(p): print(p))
func _process(delta):
2023-11-19 19:41:38 +00:00
if gait != Global.GAIT.sprinting and stamina_use:
2023-11-14 21:41:08 +00:00
stamina_attribute.being_used = false
2023-11-19 19:41:38 +00:00
if gait == Global.GAIT.sprinting and stamina_use:
2023-11-14 21:41:08 +00:00
if !stamina_attribute.can_use or stamina_attribute.current_value < stamina_energy_consumption*delta:
2023-11-19 19:41:38 +00:00
gait = Global.GAIT.running
2023-11-14 21:41:08 +00:00
return
stamina_attribute.being_used = true
stamina_attribute.current_value -= stamina_energy_consumption*delta
func _physics_process(delta):
super._physics_process(delta)
# Debug()
if !networking.is_local_authority():
if input_is_moving:
2023-11-19 19:41:38 +00:00
if gait == Global.GAIT.sprinting:
2023-11-14 21:41:08 +00:00
add_movement_input(input_direction, current_movement_data.sprint_speed,current_movement_data.sprint_acceleration)
2023-11-19 19:41:38 +00:00
elif gait == Global.GAIT.running:
2023-11-14 21:41:08 +00:00
add_movement_input(input_direction, current_movement_data.run_speed,current_movement_data.run_acceleration)
else:
add_movement_input(input_direction, current_movement_data.walk_speed,current_movement_data.walk_acceleration)
else:
add_movement_input(input_direction,0,deacceleration)
return
#------------------ Look At ------------------#
match rotation_mode:
2023-11-19 19:41:38 +00:00
Global.ROTATION_MODE.velocity_direction:
2023-11-14 21:41:08 +00:00
if input_is_moving:
ik_look_at(actual_velocity + Vector3(0.0,1.0,0.0))
2023-11-19 19:41:38 +00:00
Global.ROTATION_MODE.looking_direction:
2023-11-14 21:41:08 +00:00
ik_look_at(camera_root.SpringArm.transform.basis.z * 2.0 + Vector3(0.0,1.5,0.0))
2023-11-19 19:41:38 +00:00
Global.ROTATION_MODE.aiming:
2023-11-14 21:41:08 +00:00
ik_look_at(camera_root.SpringArm.transform.basis.z * 2.0 + Vector3(0.0,1.5,0.0))
#func Debug():
# $Status/Label.text = "InputSpeed : %s" % input_velocity.length()
# $Status/Label2.text = "ActualSpeed : %s" % get_velocity().length()