feat: implement walking and killable enemy dummy entities and player movement controller base

This commit is contained in:
DottsGit
2026-06-06 21:00:45 -04:00
parent eb9344c0bb
commit 54dfd342c2
3 changed files with 35 additions and 9 deletions
+13
View File
@@ -11,6 +11,7 @@ var max_shield: float = 100.0
var shield: float = 100.0 var shield: float = 100.0
var is_dead: bool = false var is_dead: bool = false
var time_since_last_damage: float = 0.0
var ragdoll_instance: Node3D = null var ragdoll_instance: Node3D = null
var pending_impulse: Vector3 = Vector3.ZERO var pending_impulse: Vector3 = Vector3.ZERO
var recent_attackers: Dictionary = {} var recent_attackers: Dictionary = {}
@@ -39,6 +40,16 @@ func _ready() -> void:
_update_label() _update_label()
func _process(delta: float) -> void:
if is_dead:
return
time_since_last_damage += delta
if time_since_last_damage >= 5.0 and shield < max_shield:
shield += 20.0 * delta
if shield > max_shield:
shield = max_shield
_update_label()
func take_damage(amount: float, hit_position: Vector3, source: Node = null, _impulse: Vector3 = Vector3.ZERO) -> void: func take_damage(amount: float, hit_position: Vector3, source: Node = null, _impulse: Vector3 = Vector3.ZERO) -> void:
if is_dead: if is_dead:
return return
@@ -55,6 +66,8 @@ func take_damage(amount: float, hit_position: Vector3, source: Node = null, _imp
if attacker_id != 0: if attacker_id != 0:
recent_attackers[attacker_id] = Time.get_ticks_msec() / 1000.0 recent_attackers[attacker_id] = Time.get_ticks_msec() / 1000.0
time_since_last_damage = 0.0
var dmg_taken = amount var dmg_taken = amount
if shield > 0: if shield > 0:
if shield >= amount: if shield >= amount:
+13
View File
@@ -11,6 +11,7 @@ var max_shield: float = 100.0
var shield: float = 100.0 var shield: float = 100.0
var is_dead: bool = false var is_dead: bool = false
var time_since_last_damage: float = 0.0
var recent_attackers: Dictionary = {} # attacker_id: timestamp var recent_attackers: Dictionary = {} # attacker_id: timestamp
var ragdoll_instance: Node3D = null var ragdoll_instance: Node3D = null
var pending_impulse: Vector3 = Vector3.ZERO var pending_impulse: Vector3 = Vector3.ZERO
@@ -51,6 +52,14 @@ func _physics_process(delta: float) -> void:
if is_dead: if is_dead:
return return
# Shield recharge logic
time_since_last_damage += delta
if time_since_last_damage >= 5.0 and shield < max_shield:
shield += 20.0 * delta
if shield > max_shield:
shield = max_shield
_update_label()
# Basic gravity # Basic gravity
if not is_on_floor(): if not is_on_floor():
velocity.y -= 9.8 * delta velocity.y -= 9.8 * delta
@@ -98,6 +107,8 @@ func take_damage(amount: float, hit_position: Vector3, source: Node = null, impu
if attacker_id != 0: if attacker_id != 0:
recent_attackers[attacker_id] = Time.get_ticks_msec() / 1000.0 recent_attackers[attacker_id] = Time.get_ticks_msec() / 1000.0
time_since_last_damage = 0.0
var dmg_taken = amount var dmg_taken = amount
if shield > 0: if shield > 0:
if shield >= amount: if shield >= amount:
@@ -109,6 +120,8 @@ func take_damage(amount: float, hit_position: Vector3, source: Node = null, impu
if amount > 0: if amount > 0:
health -= amount health -= amount
if health <= 0:
health = 0
_update_label() _update_label()
+9 -9
View File
@@ -499,7 +499,6 @@ func rpc_take_damage(amount: float, hit_pos: Vector3, attacker_id: int, weapon_n
if multiplayer.is_server(): if multiplayer.is_server():
var nm = get_node_or_null("/root/NetworkManager") var nm = get_node_or_null("/root/NetworkManager")
if nm and multiplayer.has_multiplayer_peer(): if nm and multiplayer.has_multiplayer_peer():
var victim_id = multiplayer.get_unique_id()
var killer_id = attacker_id var killer_id = attacker_id
var assist_ids: Array = [] var assist_ids: Array = []
@@ -722,6 +721,15 @@ func _process(delta: float) -> void:
humanoid.set_weapon(synced_weapon_path) humanoid.set_weapon(synced_weapon_path)
humanoid.set_meta("current_weapon_path", synced_weapon_path) humanoid.set_meta("current_weapon_path", synced_weapon_path)
return return
# Update UI
if is_instance_valid(health_bar):
health_bar.value = health
health_label.text = "%d / %d" % [ceil(health), max_health]
if is_instance_valid(shield_bar):
shield_bar.value = shield
shield_label.text = "%d / %d" % [ceil(shield), max_shield]
if is_dead: if is_dead:
# Continuously follow the ragdoll torso # Continuously follow the ragdoll torso
if is_instance_valid(ragdoll_instance) and is_instance_valid(camera): if is_instance_valid(ragdoll_instance) and is_instance_valid(camera):
@@ -744,14 +752,6 @@ func _process(delta: float) -> void:
shield += 20.0 * delta shield += 20.0 * delta
if shield > max_shield: if shield > max_shield:
shield = max_shield shield = max_shield
# Update UI
if is_instance_valid(health_bar):
health_bar.value = health
health_label.text = "%d / %d" % [ceil(health), max_health]
if is_instance_valid(shield_bar):
shield_bar.value = shield
shield_label.text = "%d / %d" % [ceil(shield), max_shield]
func _setup_hud() -> void: func _setup_hud() -> void:
var margin = MarginContainer.new() var margin = MarginContainer.new()