WIP: Add basic damage

This commit is contained in:
2025-01-26 23:51:44 +01:00
parent 5c360932fd
commit 66cbb87eaa
10 changed files with 97 additions and 75 deletions

View File

@ -3,6 +3,7 @@
# ---------------------------------------------------------------------
class_name PlayerInput extends CharacterBody3D
@export var health: int = 100
@export_category("PlayerInput")
@ -47,6 +48,7 @@ func _ready() -> void:
var err := _add_world_model()
if err != OK:
print("Error occured: " + str(err))
_hide_camera_mount()
_capture_mouse()
@ -64,6 +66,10 @@ func _add_world_model() -> Error :
model_mount.add_child(node)
return OK
func _hide_camera_mount() :
first_view_camera_mount.visible = 0
hud.visible = 0
var current_gun: String = "ak"
@onready var gun_mount: Node3D = $FirstPersonCameraMount/GunMount
@onready var gun_mount_anim: AnimationPlayer = $FirstPersonCameraMount/GunMount/AnimationPlayer
@ -159,6 +165,7 @@ func _rotate_camera(sens_mod: float = 1.0) -> void:
rotation.y -= look_dir.x * camera_sens * sens_mod
first_view_camera_mount.rotation.x = clamp(first_view_camera_mount.rotation.x - look_dir.y * camera_sens * sens_mod, -1.5, 1.5)
@onready var hud = $FirstPersonCameraMount/HUD
@onready var health_indicator = $FirstPersonCameraMount/HUD/HealthIndicator
@onready var fps_indicator = $FirstPersonCameraMount/HUD/FPS
func _process(delta: float) -> void:
@ -255,6 +262,11 @@ func _hit_scan_damage(Collider):
print("damaged")
func take_damage(dam: int):
print("damage")
health -= dam
print(health)
var new_health = health - dam
set_health(new_health)
if multiplayer.is_server():
set_health.rpc(new_health)
@rpc("call_local", "reliable")
func set_health(val: int):
health = val