feat: further ninja implementation

This commit is contained in:
Sara Gerretsen 2026-03-19 23:00:54 +01:00
parent edf06623b3
commit 524430003f
7 changed files with 120 additions and 28 deletions

View file

@ -6,12 +6,13 @@ extends BehaviourAction
@onready var anim := get_behaviour_tree().get_node("%AnimationPlayer") as AnimationPlayer
func _enter() -> int:
if body.target == null or body.target.global_position.distance_to(body.global_position) > target_distance:
if body.target != null and body.target.global_position.distance_to(body.global_position) <= target_distance:
return Fail
else:
var difference : Vector3 = body.global_position - body.target.global_position
var z_basis : Vector3 = body.global_basis.z
var full_angle := Vector3(z_basis.x, 0, z_basis.z).signed_angle_to(Vector3(difference.x, 0, difference.z).normalized(), Vector3.UP)
var full_angle := Vector3(z_basis.x, 0, z_basis.z).normalized().signed_angle_to(Vector3(difference.x, 0, difference.z).normalized(), Vector3.UP)
body.rotate_y(full_angle)
anim.play("run", .1)
if anim.current_animation != "run":
anim.play("run", .2)
return Success
else:
return Fail

View file

@ -5,5 +5,5 @@ extends BehaviourAction
@onready var anim := get_behaviour_tree().get_node("%AnimationPlayer") as AnimationPlayer
func _enter() -> int:
anim.play(animation_name, .1)
anim.play(animation_name, .2)
return Success

View file

@ -98,15 +98,15 @@ func _process(_delta):
height = 3.3642578
radius = 9.955078
[node name="bot" unique_id=629825830 groups=["EnemyHitbox"] instance=ExtResource("1_882u1")]
[node name="Enemy" unique_id=629825830 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(1098642975) index="0" unique_id=1675779214]
[node name="Mesh" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(750883464) index="0" unique_id=233192374]
material_override = SubResource("StandardMaterial3D_41oev")
[node name="HandR" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(1098642975) index="1" unique_id=957498611]
[node name="HandR" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(750883464) 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
@ -131,7 +131,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.7755576e-16, 0.10578142, 2
script = ExtResource("3_3hb37")
damage_group = "PlayerHitbox"
[node name="HandL" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(1098642975) index="2" unique_id=1761081841]
[node name="HandL" type="BoneAttachment3D" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(750883464) 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
@ -150,7 +150,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=1392290156]
[node name="AnimationPlayer" parent="." index="1" unique_id=1278488642]
unique_name_in_owner = true
root_motion_track = NodePath("Character/Skeleton3D:root")

View file

@ -0,0 +1,30 @@
[gd_scene format=3 uid="uid://d2i5wdxamrqev"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_b3nq0"]
height = 1.0986328
radius = 0.6591797
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5kkkq"]
transparency = 3
alpha_hash_scale = 1.0
alpha_antialiasing_mode = 0
albedo_color = Color(0.41960785, 0.62352943, 0, 0.70980394)
[sub_resource type="SphereMesh" id="SphereMesh_b3nq0"]
radius = 2.0
height = 3.0
[node name="Bush" type="Node3D" unique_id=2000109671]
[node name="HidingSpot2" type="Area3D" parent="." unique_id=1348668493 groups=["HidingSpot"]]
[node name="CollisionShape3D" type="CollisionShape3D" parent="HidingSpot2" unique_id=807995647]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4506836, 0)
shape = SubResource("CylinderShape3D_b3nq0")
debug_color = Color(0.46325266, 0.4443376, 1, 1)
[node name="Mesh" type="MeshInstance3D" parent="." unique_id=1032234117]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.20999408, 0)
material_override = SubResource("StandardMaterial3D_5kkkq")
cast_shadow = 0
mesh = SubResource("SphereMesh_b3nq0")

View file

@ -2,7 +2,7 @@
[ext_resource type="PackedScene" uid="uid://hirlnhjbqv2u" path="res://assets/characters/bot.blend" id="1_fssyu"]
[ext_resource type="Script" uid="uid://bm6unenoiyy5h" path="res://behaviours/follow_target.gd" id="2_klwnj"]
[ext_resource type="Script" uid="uid://b2s7gavo263mo" path="res://behaviours/npc_idle.gd" id="3_klwnj"]
[ext_resource type="Script" uid="uid://bp4utstetxnhr" path="res://behaviours/animate.gd" id="3_klwnj"]
[ext_resource type="PackedScene" uid="uid://deuif6d8spece" path="res://objects/awareness_area.tscn" id="3_tpgvx"]
[sub_resource type="GDScript" id="GDScript_klwnj"]
@ -20,6 +20,31 @@ func _physics_process(delta : float):
move_and_slide()
"
[sub_resource type="GDScript" id="GDScript_jh7vn"]
resource_name = "EnemyInPlayerRange"
script/source = "extends BehaviourAction
@onready var body := get_behaviour_tree().get_parent() as CharacterBody3D
func _enter() -> int:
return Fail if body.find_targets().is_empty() else Success
"
[sub_resource type="GDScript" id="GDScript_exeof"]
resource_name = "SelectHidingSpot"
script/source = "extends BehaviourAction
var body := get_behaviour_tree().get_parent() as CharacterBody3D
func _enter() -> int:
var spot : Node3D = body.get_hiding_spot()
if spot:
body.target = spot
return Success
else:
return Fail
"
[sub_resource type="GDScript" id="GDScript_tpgvx"]
resource_name = "SelectPlayer"
script/source = "extends BehaviourAction
@ -37,7 +62,7 @@ albedo_color = Color(0.4745098, 0.16862746, 0.61960787, 1)
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_lyptg"]
radius = 0.30273438
[node name="bot" unique_id=1341242765 instance=ExtResource("1_fssyu")]
[node name="Ninja" unique_id=1341242765 instance=ExtResource("1_fssyu")]
script = SubResource("GDScript_klwnj")
[node name="BehaviourTree" type="BehaviourTree" parent="." index="0" unique_id=1843075231]
@ -46,18 +71,29 @@ script = SubResource("GDScript_klwnj")
[node name="BehaviourSelector" type="BehaviourSelector" parent="BehaviourTree/BehaviourRepeater" index="0" unique_id=487995934]
[node name="FollowPlayer" type="BehaviourSequence" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector" index="0" unique_id=1977466711]
[node name="SequenceCombat" type="BehaviourSequence" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector" index="0" unique_id=664462649]
[node name="SelectPlayer" type="BehaviourAction" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector/FollowPlayer" index="0" unique_id=92830272]
[node name="EnemyInPlayerRange" type="BehaviourAction" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector/SequenceCombat" index="0" unique_id=1499130003]
script = SubResource("GDScript_jh7vn")
[node name="SelectHidingSpot" type="BehaviourAction" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector/SequenceCombat" index="1" unique_id=1743644615]
script = SubResource("GDScript_exeof")
[node name="SequenceFollowPlayer" type="BehaviourSequence" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector" index="1" unique_id=1977466711]
[node name="SelectPlayer" type="BehaviourAction" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector/SequenceFollowPlayer" index="0" unique_id=92830272]
script = SubResource("GDScript_tpgvx")
[node name="FollowTarget" type="BehaviourAction" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector/FollowPlayer" index="1" unique_id=282888066]
[node name="FollowTarget" type="BehaviourAction" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector/SequenceFollowPlayer" index="1" unique_id=282888066]
script = ExtResource("2_klwnj")
target_distance = 3.0
[node name="Idle" type="BehaviourAction" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector" index="1" unique_id=1038185599]
[node name="Idle" type="BehaviourAction" parent="BehaviourTree/BehaviourRepeater/BehaviourSelector" index="2" unique_id=1038185599]
script = ExtResource("3_klwnj")
animation_name = "duck"
anim_name = "duck"
allow_interrupt = false
wait_for_finish = false
blend = 0.2
[node name="Mesh" parent="Character/Skeleton3D" parent_id_path=PackedInt32Array(750883464) index="0" unique_id=233192374]
material_override = SubResource("StandardMaterial3D_lyptg")
@ -70,6 +106,9 @@ root_motion_track = NodePath("Character/Skeleton3D:root")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("CapsuleShape3D_lyptg")
[node name="AwarenessArea" parent="." index="4" unique_id=986494999 instance=ExtResource("3_tpgvx")]
[node name="HidingSpotAwareness" parent="." index="4" unique_id=986494999 instance=ExtResource("3_tpgvx")]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.92650235, 0)
target_group = "HidingSpot"
[editable path="HidingSpotAwareness"]

View file

@ -138,7 +138,7 @@ size = Vector3(0.33496094, 0.8294678, 0.4711914)
height = 1.8466797
radius = 0.89404297
[node name="bot" unique_id=1341242765 groups=["PlayerHitbox"] instance=ExtResource("1_eqqp1")]
[node name="Player" unique_id=1341242765 groups=["PlayerHitbox"] instance=ExtResource("1_eqqp1")]
collision_layer = 2
collision_mask = 3
script = SubResource("GDScript_eqqp1")

View file

@ -7,6 +7,7 @@
[ext_resource type="PackedScene" uid="uid://1s2obm2l4f1a" path="res://objects/enemy.tscn" id="2_w0s2s"]
[ext_resource type="PackedScene" uid="uid://cu1nh3rbcnn3w" path="res://objects/ninja.tscn" id="4_b3nq0"]
[ext_resource type="PackedScene" uid="uid://djv4uhdtykukm" path="res://objects/arming_sword.tscn" id="5_hyc8p"]
[ext_resource type="PackedScene" uid="uid://d2i5wdxamrqev" path="res://objects/hiding_spot.tscn" id="8_cryqq"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_upt1h"]
sky_horizon_color = Color(0.66224277, 0.6717428, 0.6867428, 1)
@ -114,29 +115,50 @@ path = [NodePath("../Marker3D"), NodePath("../Marker3D2"), NodePath("../Marker3D
transform = Transform3D(0.7200159, -0.69395757, -3.0333847e-08, 0, -4.371139e-08, 1, -0.69395757, -0.7200159, -3.1472894e-08, 0.15892982, 0.030806396, -2.3319297)
[node name="Marker3D" type="Marker3D" parent="." unique_id=1303933571]
transform = Transform3D(-0.9973041, 0.063548714, -0.036689803, 5.1930144e-08, 0.5000001, 0.86602545, 0.073379725, 0.86369073, -0.4986521, -7.769764, 0, 1.7417345)
transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1, -7.769764, 0, 1.7417345)
[node name="Marker3D2" type="Marker3D" parent="." unique_id=674175897]
transform = Transform3D(-0.9973041, 0.063548714, -0.036689803, 5.1930144e-08, 0.5000001, 0.86602545, 0.073379725, 0.86369073, -0.4986521, 5.1349115, 0, 3.6002054)
transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1, 5.1349115, 0, 3.6002054)
[node name="Marker3D3" type="Marker3D" parent="." unique_id=1901575138]
transform = Transform3D(-0.9973041, 0.063548714, -0.036689803, 5.1930144e-08, 0.5000001, 0.86602545, 0.073379725, 0.86369073, -0.4986521, 5.9668307, 0, -5.7310467)
transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1, 5.9668307, 0, -5.7310467)
[node name="Marker3D4" type="Marker3D" parent="." unique_id=1864554328]
transform = Transform3D(-0.9973041, 0.063548714, -0.036689803, 5.1930144e-08, 0.5000001, 0.86602545, 0.073379725, 0.86369073, -0.4986521, -7.3572216, 0, -6.262743)
transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1, -7.3572216, 0, -6.262743)
[node name="Enemy2" parent="." unique_id=1129420379 node_paths=PackedStringArray("path") instance=ExtResource("2_w0s2s")]
transform = Transform3D(0.3496833, 0, -0.93686795, 0, 1, 0, 0.93686795, 0, 0.3496833, -0.5668974, 0, 16.554804)
path = [NodePath("../Marker3D5"), NodePath("../Marker3D6"), NodePath("../Marker3D7"), NodePath("../Marker3D8")]
[node name="Marker3D5" type="Marker3D" parent="." unique_id=910557975]
transform = Transform3D(-0.99730414, 0.063548714, -0.036689814, 5.1930144e-08, 0.5000001, 0.86602545, 0.07337972, 0.8636908, -0.49865213, -7.7697635, 0, 21.450317)
transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1.0000001, -7.7697635, 0, 21.450317)
[node name="Marker3D6" type="Marker3D" parent="." unique_id=1012680820]
transform = Transform3D(-0.99730414, 0.063548714, -0.036689814, 5.1930144e-08, 0.5000001, 0.86602545, 0.07337972, 0.8636908, -0.49865213, 5.134912, 0, 23.308786)
transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1.0000001, 5.134912, 0, 23.308786)
[node name="Marker3D7" type="Marker3D" parent="." unique_id=431098883]
transform = Transform3D(-0.99730414, 0.063548714, -0.036689814, 5.1930144e-08, 0.5000001, 0.86602545, 0.07337972, 0.8636908, -0.49865213, 5.9668317, 0, 13.977535)
transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1.0000001, 5.9668317, 0, 13.977535)
[node name="Marker3D8" type="Marker3D" parent="." unique_id=1084672519]
transform = Transform3D(-0.99730414, 0.063548714, -0.036689814, 5.1930144e-08, 0.5000001, 0.86602545, 0.07337972, 0.8636908, -0.49865213, -7.357221, 0, 13.445837)
transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1.0000001, -7.357221, 0, 13.445837)
[node name="HidingSpot" parent="." unique_id=1032234117 instance=ExtResource("8_cryqq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5972681, 0, -5.8054976)
[node name="HidingSpot2" parent="." unique_id=1657310597 instance=ExtResource("8_cryqq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.3118906, 0, -7.345297)
[node name="HidingSpot3" parent="." unique_id=1185290802 instance=ExtResource("8_cryqq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.5202894, 0, 9.844728)
[node name="HidingSpot4" parent="." unique_id=1683074918 instance=ExtResource("8_cryqq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5001755, 0, 8.74155)
[node name="HidingSpot5" parent="." unique_id=428242929 instance=ExtResource("8_cryqq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.0010672, 0, 10.866992)
[node name="HidingSpot6" parent="." unique_id=1358940505 instance=ExtResource("8_cryqq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.922848, 0, 16.623213)
[node name="HidingSpot7" parent="." unique_id=1978438261 instance=ExtResource("8_cryqq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -13.385458, 9.536743e-07, 15.360628)