feat: implemented patrol behaviour

This commit is contained in:
Sara Gerretsen 2026-03-18 15:07:56 +01:00
parent 425525e56f
commit 8dbc7fc4ac
23 changed files with 270 additions and 139 deletions

View file

@ -11,12 +11,13 @@ resource_name = "EnemyBody"
script/source = "extends CharacterBody3D
signal damaged(amount : int, source : Node3D)
@export var health : int = 6
@export var path : Array[Marker3D]
@onready var anim := %AnimationPlayer as AnimationPlayer
var hurt_high : bool = false
var target : Node3D = null
var patrol_target : int = 0
func _ready():
damaged.connect(_damaged)
@ -25,6 +26,8 @@ func _damaged(amount : int, source : Node3D):
hurt_high = true
target = source
health -= amount
if health <= 0:
%WeaponParent.drop_weapon()
func _physics_process(delta : float):
var motion := anim.get_root_motion_position()
@ -32,6 +35,9 @@ func _physics_process(delta : float):
velocity += get_gravity() * delta
move_and_slide()
func equip_weapon(weapon : Area3D):
%WeaponParent.set_weapon(weapon)
func get_current_weapon_type() -> String:
return \"\" if %WeaponParent.weapon == null else %WeaponParent.weapon.animations
@ -61,15 +67,15 @@ radius = 0.2133789
height = 3.3642578
radius = 9.955078
[node name="bot" unique_id=161717875 groups=["EnemyHitbox"] instance=ExtResource("1_882u1")]
[node name="bot" unique_id=1620071502 groups=["EnemyHitbox"] instance=ExtResource("1_882u1")]
collision_layer = 2
collision_mask = 3
script = SubResource("GDScript_882u1")
[node name="Mesh" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(1480016001) index="0" unique_id=825969686]
[node name="Mesh" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(2131828200) index="0" unique_id=979271948]
material_override = SubResource("StandardMaterial3D_41oev")
[node name="HandR" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(1480016001) index="1" unique_id=957498611]
[node name="HandR" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(2131828200) index="1" unique_id=957498611]
transform = Transform3D(0.015967373, -0.083946444, 0.9963424, -0.17989334, -0.98045003, -0.07972447, 0.9835564, -0.17796235, -0.030756809, 0.27221423, 0.7951686, 0.024477992)
bone_name = "hand.r"
bone_idx = 10
@ -92,10 +98,9 @@ debug_color = Color(0.9966913, 0, 0.17880186, 1)
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.7755576e-16, 0.10578142, 2.095476e-09)
script = ExtResource("3_3hb37")
damage_group = "EnemyHitbox"
deal_damage = true
damage_group = "PlayerHitbox"
[node name="HandL" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(1480016001) index="2" unique_id=1761081841]
[node name="HandL" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(2131828200) index="2" unique_id=1761081841]
transform = Transform3D(-0.039434362, 0.07924447, -0.9960749, 0.12679999, -0.9883944, -0.083653376, -0.99114394, -0.12960118, 0.028928574, -0.2710728, 0.7714727, 0.0945672)
bone_name = "hand.l"
bone_idx = 7
@ -114,7 +119,7 @@ transform = Transform3D(1.0000169, -1.5795231e-06, -3.874302e-07, 8.046627e-07,
shape = SubResource("BoxShape3D_we7g8")
debug_color = Color(0.9966913, 0, 0.17880186, 1)
[node name="AnimationPlayer" parent="." index="1" unique_id=2115366661]
[node name="AnimationPlayer" parent="." index="1" unique_id=741852883]
unique_name_in_owner = true
root_motion_track = NodePath("Character/Skeleton3D:root")
@ -132,6 +137,7 @@ shape = SubResource("CylinderShape3D_we7g8")
[node name="ItemAwareness" parent="." index="5" unique_id=697341779 instance=ExtResource("4_we7g8")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.0324535, 0)
collision_mask = 1
target_group = "WeaponPickup"
[node name="CollisionShape3D" parent="ItemAwareness" index="0" unique_id=2035583636]

View file

@ -84,7 +84,8 @@ func wants_backstep() -> bool:
"
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_eqqp1"]
radius = 0.21240234
radius = 0.2783203
height = 2.112793
[sub_resource type="GDScript" id="GDScript_nmc1l"]
resource_name = "CameraPivot"
@ -131,7 +132,7 @@ size = Vector3(0.33496094, 0.8294678, 0.4711914)
height = 1.8466797
radius = 0.8466797
[node name="bot" unique_id=101509437 groups=["PlayerHitbox"] instance=ExtResource("1_eqqp1")]
[node name="bot" unique_id=1620071502 groups=["PlayerHitbox"] instance=ExtResource("1_eqqp1")]
collision_layer = 2
collision_mask = 3
script = SubResource("GDScript_eqqp1")
@ -139,7 +140,7 @@ script = SubResource("GDScript_eqqp1")
[node name="PlayerBehaviours" parent="." index="0" unique_id=2061972400 instance=ExtResource("2_uxov2")]
[node name="PhysicsShape" type="CollisionShape3D" parent="." index="1" unique_id=1611683515]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.0563965, 0)
shape = SubResource("CapsuleShape3D_eqqp1")
debug_color = Color(0, 0.6, 0.69803923, 1)
@ -148,11 +149,11 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.0963671, 0)
target_group = "EnemyHitbox"
[node name="CameraPivot" type="Node3D" parent="." index="3" unique_id=1714065679]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.7066379, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.6702702, 0)
script = SubResource("GDScript_nmc1l")
[node name="SpringArm3D" type="SpringArm3D" parent="CameraPivot" index="0" unique_id=1656112632]
transform = Transform3D(0.98211235, 0, 0.18829599, 0, 1, 0, -0.18829599, 0, 0.98211235, 0.06544638, 0.5373664, 0)
transform = Transform3D(0.98211235, 0, 0.18829599, 0, 1, 0, -0.18829599, 0, 0.98211235, -0.014201134, 0.2906257, -0.0010317713)
shape = SubResource("SphereShape3D_nmc1l")
spring_length = 4.0
@ -161,10 +162,10 @@ transform = Transform3D(0.981895, -5.3638707e-09, -0.18942553, 5.529141e-09, 1,
current = true
fov = 52.5
[node name="Mesh" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(1480016001) index="0" unique_id=825969686]
[node name="Mesh" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(2131828200) index="0" unique_id=979271948]
material_override = SubResource("StandardMaterial3D_f46kd")
[node name="HandR" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(1480016001) index="1" unique_id=385862689]
[node name="HandR" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(2131828200) index="1" unique_id=385862689]
transform = Transform3D(0.015967373, -0.083946444, 0.9963424, -0.17989334, -0.98045003, -0.07972447, 0.9835564, -0.17796235, -0.030756809, 0.27221423, 0.7951686, 0.024477992)
bone_name = "hand.r"
bone_idx = 10
@ -189,7 +190,7 @@ script = ExtResource("5_f46kd")
damage_group = "EnemyHitbox"
deal_damage = true
[node name="HandL" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(1480016001) index="2" unique_id=279793409]
[node name="HandL" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(2131828200) index="2" unique_id=279793409]
transform = Transform3D(-0.039434362, 0.07924447, -0.9960749, 0.12679999, -0.9883944, -0.083653376, -0.99114394, -0.12960118, 0.028928574, -0.2710728, 0.7714727, 0.0945672)
bone_name = "hand.l"
bone_idx = 7
@ -207,7 +208,7 @@ transform = Transform3D(1.0000169, -1.5944242e-06, -4.04194e-07, 6.556511e-07, 1
shape = SubResource("BoxShape3D_uxov2")
debug_color = Color(0.9966913, 0, 0.17880186, 1)
[node name="LegR" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(1480016001) index="3" unique_id=2088257762]
[node name="LegR" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(2131828200) index="3" unique_id=2088257762]
transform = Transform3D(0.9947343, 0.10095803, 0.017639676, 0.10222586, -0.98967797, -0.1004331, 0.0073180734, 0.1017075, -0.9947873, 0.14436838, 0.42896914, -0.076926425)
bone_name = "leg.lower.r"
bone_idx = 14
@ -225,7 +226,7 @@ transform = Transform3D(1, -5.960372e-07, -1.0579633e-06, 5.960361e-07, 1, -1.03
shape = SubResource("BoxShape3D_nmc1l")
debug_color = Color(0.9966913, 0, 0.17880186, 1)
[node name="AnimationPlayer" parent="." index="5" unique_id=2115366661]
[node name="AnimationPlayer" parent="." index="5" unique_id=741852883]
unique_name_in_owner = true
root_motion_track = NodePath("Character/Skeleton3D:root")