Basic PUG Behaviour okayish.

main
Martin Felis 2024-12-28 18:30:23 +01:00
parent 5f004b07e9
commit bdb29ebcef
13 changed files with 190 additions and 47 deletions

View File

@ -5,9 +5,9 @@ extends BTAction
@export var output_var: StringName = &"location_distance"
func _generate_name() -> String:
return "CalcDistanceToLocation \"%s\" -> %s" % [
target_location_var,
output_var
return "CalcDistanceToLocation(%s) ➜ %s" % [
LimboUtility.decorate_var(target_location_var),
LimboUtility.decorate_var(output_var)
]
func _tick(_delta: float) -> Status:

View File

@ -0,0 +1,31 @@
@tool
extends BTAction
@export var target_node_var: StringName = &"target_node"
const RAY_OFFSET:Vector3 = Vector3.UP * 0.5
var _physics_ray_query_parameters:PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.new()
func _generate_name() -> String:
return "CheckNodeVisible(%s)" % [
LimboUtility.decorate_var(target_node_var)
]
func _tick(_delta: float) -> Status:
var target_node:Node3D = blackboard.get_var(target_node_var)
var agent_node:Node3D = agent as Node3D
var world_space_state:PhysicsDirectSpaceState3D = agent_node.get_world_3d().direct_space_state
var source_position:Vector3 = agent_node.global_position + RAY_OFFSET
var target_position:Vector3 = target_node.global_position + RAY_OFFSET
_physics_ray_query_parameters.from = source_position
_physics_ray_query_parameters.to = target_position
_physics_ray_query_parameters.collision_mask = 32 + 1
var result:Dictionary = world_space_state.intersect_ray(_physics_ray_query_parameters)
if result.is_empty():
return SUCCESS
return FAILURE

View File

@ -2,10 +2,10 @@
extends BTAction
@export var target_name: String = ""
@export var output_var: StringName = &"target"
@export var output_var: StringName = &"target_node"
func _generate_name() -> String:
return "FindTargetByName \"%s\"%s" % [
return "FindTargetByName(\"%s\") ➜ %s" % [
target_name,
LimboUtility.decorate_var(output_var)
]

View File

@ -6,9 +6,9 @@ extends BTAction
@export var output_var: StringName = &"target_location"
func _generate_name() -> String:
return "GetTargetLocation \"%s\"%s" % [
target_var,
LimboUtility.decorate_var(target_var)
return "GetTargetLocation(%s) ➜ %s" % [
LimboUtility.decorate_var(target_var),
LimboUtility.decorate_var(output_var)
]
func _tick(_delta: float) -> Status:

View File

@ -12,7 +12,7 @@ var _target_look_angle:float = 0
var _look_angle_damper:SpringDamper = SpringDamper.new(0, 2, 0.06, 0.003)
func _generate_name() -> String:
return "Look at Target " + LimboUtility.decorate_var(target_location_var)
return "LookAtTarget(%s)" % LimboUtility.decorate_var(target_location_var)
func _tick(delta: float) -> Status:
target_position = blackboard.get_var(target_location_var)

View File

@ -1,15 +1,106 @@
[gd_resource type="BehaviorTree" load_steps=5 format=3 uid="uid://blccr23qjixws"]
[gd_resource type="BehaviorTree" load_steps=30 format=3 uid="uid://blccr23qjixws"]
[ext_resource type="BehaviorTree" uid="uid://caxmpcyhpt6em" path="res://ai/trees/wander.tres" id="1_rsg0c"]
[ext_resource type="Script" path="res://ai/tasks/find_target_by_name.gd" id="1_v4edy"]
[ext_resource type="Script" path="res://ai/tasks/navigate_to_location.gd" id="2_k36i0"]
[ext_resource type="Script" path="res://ai/tasks/get_target_location.gd" id="2_ytv0s"]
[ext_resource type="Script" path="res://ai/tasks/calc_distance_to_location.gd" id="3_wfof3"]
[ext_resource type="Script" path="res://ai/tasks/check_target_node_visible.gd" id="4_dskwm"]
[ext_resource type="Script" path="res://ai/tasks/look_at_location.gd" id="5_s0awd"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_yg732"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_x4gxn"]
[sub_resource type="BTAction" id="BTAction_u48vm"]
script = ExtResource("1_v4edy")
target_name = "Player"
output_var = &"player_node"
[sub_resource type="BTSubtree" id="BTSubtree_krik0"]
[sub_resource type="BTAction" id="BTAction_iv8pd"]
script = ExtResource("2_ytv0s")
max_distance = 1.0
target_var = &"player_node"
output_var = &"player_location"
[sub_resource type="BTAction" id="BTAction_n4o2j"]
script = ExtResource("3_wfof3")
target_location_var = &"player_location"
output_var = &"player_distance"
[sub_resource type="BTAction" id="BTAction_dafbx"]
script = ExtResource("1_v4edy")
target_name = "Timmy"
output_var = &"owner_node"
[sub_resource type="BTAction" id="BTAction_byeb5"]
script = ExtResource("2_ytv0s")
max_distance = 1.0
target_var = &"owner_node"
output_var = &"owner_location"
[sub_resource type="BTAction" id="BTAction_6cy6k"]
script = ExtResource("3_wfof3")
target_location_var = &"owner_location"
output_var = &"owner_distance"
[sub_resource type="BBVariant" id="BBVariant_doyi6"]
type = 3
saved_value = 3.0
resource_name = "3"
[sub_resource type="BTCheckVar" id="BTCheckVar_nbtfc"]
variable = &"owner_distance"
check_type = 2
value = SubResource("BBVariant_doyi6")
[sub_resource type="BTAction" id="BTAction_6rb0n"]
script = ExtResource("2_k36i0")
target_var = &"owner_location"
[sub_resource type="BTSequence" id="BTSequence_bn3or"]
custom_name = "WanderNearTimmy"
children = [SubResource("BTCheckVar_nbtfc"), SubResource("BTAction_6rb0n")]
[sub_resource type="BBVariant" id="BBVariant_55npk"]
type = 3
saved_value = 5.0
resource_name = "5"
[sub_resource type="BTCheckVar" id="BTCheckVar_0y1pg"]
variable = &"player_distance"
check_type = 2
value = SubResource("BBVariant_55npk")
[sub_resource type="BTAction" id="BTAction_07lxa"]
script = ExtResource("4_dskwm")
target_node_var = &"player_node"
[sub_resource type="BTAction" id="BTAction_12d23"]
script = ExtResource("5_s0awd")
target_location_var = &"player_location"
[sub_resource type="BTAction" id="BTAction_euy6e"]
script = ExtResource("2_k36i0")
target_var = &"player_location"
[sub_resource type="BTParallel" id="BTParallel_ocd8a"]
children = [SubResource("BTAction_12d23"), SubResource("BTAction_euy6e")]
[sub_resource type="BTSequence" id="BTSequence_jneh0"]
custom_name = "FollowPlayerOrWanderSequence"
children = [SubResource("BTCheckVar_0y1pg"), SubResource("BTAction_07lxa"), SubResource("BTParallel_ocd8a")]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_byw02"]
[sub_resource type="BTSubtree" id="BTSubtree_clqa0"]
subtree = ExtResource("1_rsg0c")
blackboard_plan = SubResource("BlackboardPlan_x4gxn")
blackboard_plan = SubResource("BlackboardPlan_byw02")
[sub_resource type="BTSelector" id="BTSelector_dolqa"]
children = [SubResource("BTSequence_bn3or"), SubResource("BTSequence_jneh0"), SubResource("BTSubtree_clqa0")]
[sub_resource type="BTSequence" id="BTSequence_y2c1w"]
children = [SubResource("BTAction_u48vm"), SubResource("BTAction_iv8pd"), SubResource("BTAction_n4o2j"), SubResource("BTAction_dafbx"), SubResource("BTAction_byeb5"), SubResource("BTAction_6cy6k"), SubResource("BTSelector_dolqa")]
[resource]
blackboard_plan = SubResource("BlackboardPlan_yg732")
root_task = SubResource("BTSubtree_krik0")
root_task = SubResource("BTSequence_y2c1w")

View File

@ -3,9 +3,10 @@
[ext_resource type="PackedScene" uid="uid://bbtp6w3ubgt0k" path="res://assets/scene_props/wall_segment.tscn" id="1_1uh55"]
[node name="LogCabin" type="Node3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 13, -0.5, -3)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.524584, -0.5, 0.326459)
[node name="WallSegment6" parent="." instance=ExtResource("1_1uh55")]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 1.501, 0.5, -1.498)
[node name="WallSegment7" parent="." instance=ExtResource("1_1uh55")]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.5, 0.5, -1.5)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://bbtp6w3ubgt0k"]
[gd_scene load_steps=7 format=3 uid="uid://bbtp6w3ubgt0k"]
[sub_resource type="BoxShape3D" id="BoxShape3D_0hyct"]
size = Vector3(0.25, 1, 1)
@ -21,8 +21,14 @@ texture_filter = 0
material = SubResource("StandardMaterial3D_rvqit")
size = Vector3(0.25, 1, 1)
[sub_resource type="NavigationMesh" id="NavigationMesh_u1aw7"]
vertices = PackedVector3Array(-0.125, 0.5, 0.5, 0.125, 0.5, -0.5, 0.125, 0.5, 0.5, -0.125, 0.5, -0.5, -0.125, -0.5, 0.5, 0.125, -0.5, -0.5, 0.125, -0.5, 0.5, -0.125, -0.5, -0.5, 0.125, 0.5, 0.5, -0.125, 0.5, -0.5, 0.125, 0.5, -0.5, -0.125, 0.5, 0.5, 0.125, -0.5, 0.5, -0.125, -0.5, -0.5, 0.125, -0.5, -0.5, -0.125, -0.5, 0.5, 0.125, 0.5, 0.5, -0.125, -0.5, 0.5, -0.125, 0.5, 0.5, 0.125, -0.5, 0.5, 0.125, 0.5, -0.5, -0.125, -0.5, -0.5, -0.125, 0.5, -0.5, 0.125, -0.5, -0.5)
polygons = [PackedInt32Array(0, 2, 4), PackedInt32Array(2, 6, 4), PackedInt32Array(1, 3, 5), PackedInt32Array(3, 7, 5), PackedInt32Array(8, 10, 12), PackedInt32Array(10, 14, 12), PackedInt32Array(9, 11, 13), PackedInt32Array(11, 15, 13), PackedInt32Array(16, 18, 20), PackedInt32Array(18, 22, 20), PackedInt32Array(17, 19, 21), PackedInt32Array(19, 23, 21)]
[node name="WallSegment6" type="StaticBody3D"]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 1.5, 0.5, -1.5)
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 0)
collision_layer = 32
collision_mask = 0
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
@ -32,3 +38,6 @@ shape = SubResource("BoxShape3D_0hyct")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("BoxMesh_0lmcs")
skeleton = NodePath("../..")
[node name="NavigationRegion3D" type="NavigationRegion3D" parent="MeshInstance3D"]
navigation_mesh = SubResource("NavigationMesh_u1aw7")

View File

@ -91,5 +91,5 @@ func is_target_navigatable(target_position: Vector3) -> bool:
func navigate_to(target_position: Vector3) -> void:
navigation_agent.target_position = target_position
assert (is_target_navigatable(target_position))
# assert (is_target_navigatable(target_position))
navigation_active = not navigation_agent.is_target_reached()

View File

@ -27,6 +27,8 @@ radius = 1.0
[sub_resource type="BlackboardPlan" id="BlackboardPlan_yqrfn"]
[node name="NonPlayerCharacter" type="CharacterBody3D" groups=["non_player_character"]]
collision_layer = 64
collision_mask = 67
script = ExtResource("1_c2apr")
behaviour = ExtResource("2_3dryb")
@ -37,6 +39,7 @@ shape = SubResource("CylinderShape3D_uynrb")
[node name="DefaultGeometry" parent="." instance=ExtResource("1_25fog")]
unique_name_in_owner = true
transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0)
visible = false
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
unique_name_in_owner = true

View File

@ -144,7 +144,8 @@ transitions = ["Start", "rogue_Idle", SubResource("AnimationNodeStateMachineTran
graph_offset = Vector2(-12, 57.7514)
[node name="Player" type="CharacterBody3D"]
collision_layer = 3
collision_layer = 2
collision_mask = 99
script = ExtResource("1_qkf7c")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
@ -170,7 +171,7 @@ unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.98728)
[node name="RightHandBone" type="BoneAttachment3D" parent="."]
transform = Transform3D(-0.000355374, -0.0615158, 0.395241, 0.399997, -0.0015009, 0.000125934, 0.00146382, 0.395238, 0.0615168, -0.196426, 0.253977, 0.0423942)
transform = Transform3D(-0.0010606, -0.0645303, 0.394759, 0.399975, -0.00441319, 0.000353067, 0.00429856, 0.394736, 0.0645381, -0.19614, 0.249861, 0.0430095)
bone_name = "Knife"
bone_idx = 17
use_external_skeleton = true
@ -190,31 +191,31 @@ transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0)
[node name="Skeleton3D" parent="Geometry/Rogue/Rig" index="0"]
bones/0/rotation = Quaternion(0, 1.19209e-07, 0, 1)
bones/1/position = Vector3(0, 0.389752, 0)
bones/1/position = Vector3(0, 0.368152, 0)
bones/1/rotation = Quaternion(-1.11123e-10, 0.0431578, 2.57241e-09, 0.999068)
bones/2/rotation = Quaternion(0, 7.10543e-15, 0, 1)
bones/4/position = Vector3(0.212007, 0.134132, 8.40246e-08)
bones/4/rotation = Quaternion(-0.55801, -0.0619593, -0.648941, 0.51348)
bones/5/rotation = Quaternion(1.96982e-08, -4.3963e-08, -0.486423, 0.873723)
bones/7/rotation = Quaternion(-0.319509, -0.325501, 0.141342, 0.878627)
bones/4/rotation = Quaternion(-0.550562, -0.0569332, -0.640382, 0.532496)
bones/5/rotation = Quaternion(4.26205e-08, -3.37907e-08, -0.512092, 0.85893)
bones/7/rotation = Quaternion(-0.320528, -0.338814, 0.147834, 0.872131)
bones/8/position = Vector3(8.34815e-10, 0.0961251, -0.0575001)
bones/8/rotation = Quaternion(0.000690466, 0.000690435, -0.704567, 0.709636)
bones/8/rotation = Quaternion(0.00121838, 0.00121838, -0.70262, 0.711563)
bones/10/position = Vector3(-0.212007, 0.134132, 8.40246e-08)
bones/10/rotation = Quaternion(-0.616723, 0.0818303, 0.62242, 0.474921)
bones/11/rotation = Quaternion(2.05049e-08, 5.23177e-08, 0.510019, 0.860163)
bones/13/rotation = Quaternion(-0.317791, 0.300232, -0.222949, 0.8713)
bones/10/rotation = Quaternion(-0.609342, 0.077468, 0.615692, 0.493583)
bones/11/rotation = Quaternion(5.15856e-08, 5.32673e-08, 0.534607, 0.845101)
bones/13/rotation = Quaternion(-0.31965, 0.314774, -0.230016, 0.863617)
bones/14/position = Vector3(-8.34815e-10, 0.0961251, -0.0575001)
bones/14/rotation = Quaternion(0.00127961, 0.00150719, 0.705778, 0.70843)
bones/14/rotation = Quaternion(0.00376201, 0.0044311, 0.703185, 0.710983)
bones/19/rotation = Quaternion(-5.8061e-11, -0.0313416, -1.88013e-09, 0.999509)
bones/21/position = Vector3(0.170945, 0.113587, 1.39233e-08)
bones/21/rotation = Quaternion(0.993492, 0.0834361, 0.0743162, 0.0221156)
bones/22/rotation = Quaternion(0.224683, 6.63181e-08, -1.53341e-07, 0.974432)
bones/23/rotation = Quaternion(-0.532678, -0.208619, 0.0480771, 0.818792)
bones/21/rotation = Quaternion(0.98935, 0.0838184, 0.0788919, 0.0890948)
bones/22/rotation = Quaternion(0.400425, 5.67776e-08, -2.71737e-07, 0.91633)
bones/23/rotation = Quaternion(-0.624352, -0.200486, 0.0777503, 0.750963)
bones/24/rotation = Quaternion(-3.04797e-08, 0.920355, -0.391084, 6.94849e-08)
bones/25/position = Vector3(-0.170945, 0.113587, 1.39233e-08)
bones/25/rotation = Quaternion(0.996786, -0.029905, 0.0313134, 0.0673989)
bones/26/rotation = Quaternion(0.295482, -6.32887e-08, 2.05301e-07, 0.955348)
bones/27/rotation = Quaternion(-0.570454, 0.114367, -0.0104161, 0.813262)
bones/25/rotation = Quaternion(0.991162, -0.0335157, 0.0297454, 0.124861)
bones/26/rotation = Quaternion(0.444001, -5.88264e-08, 3.12121e-07, 0.896026)
bones/27/rotation = Quaternion(-0.650146, 0.112372, -0.0238416, 0.751075)
bones/28/rotation = Quaternion(3.04797e-08, 0.920355, -0.391084, -6.94849e-08)
bones/29/position = Vector3(0.170945, 0.29231, 0.575812)
bones/29/rotation = Quaternion(0.707107, -2.29302e-07, -4.60551e-08, 0.707107)
@ -238,30 +239,30 @@ bones/40/position = Vector3(-6.31128e-09, 0.16565, 1.36608e-09)
bones/41/rotation = Quaternion(1, 4.44086e-16, 1.94707e-07, 6.91739e-22)
bones/43/position = Vector3(0.453507, 1.10676, -0.588859)
bones/43/rotation = Quaternion(-0.707107, -7.27951e-08, -7.27951e-08, 0.707107)
bones/44/position = Vector3(0.520841, 0.782657, -0.0576374)
bones/44/position = Vector3(0.520841, 0.77165, -0.0576374)
bones/44/rotation = Quaternion(0.794627, -1.2666e-07, 0.607098, -5.96046e-08)
bones/45/position = Vector3(-0.453507, 1.10676, -0.58886)
bones/45/rotation = Quaternion(-0.707107, -7.27951e-08, -7.27951e-08, 0.707107)
bones/46/position = Vector3(-0.510844, 0.782657, 0.0597369)
bones/46/position = Vector3(-0.510844, 0.77165, 0.0597369)
bones/46/rotation = Quaternion(-0.758253, -1.82539e-07, 0.651961, -1.11759e-08)
[node name="Knife_Offhand" parent="Geometry/Rogue/Rig/Skeleton3D" index="0"]
transform = Transform3D(5.20757e-06, 0.262874, 0.96483, 0.999971, -0.00716806, 0.00194798, 0.00742836, 0.964803, -0.262867, 0.507662, 0.630718, -0.0191397)
transform = Transform3D(-1.88394e-07, 0.262864, 0.964832, 0.999913, -0.0126474, 0.00344631, 0.0131088, 0.96475, -0.262841, 0.50728, 0.620143, -0.017604)
[node name="1H_Crossbow" parent="Geometry/Rogue/Rig/Skeleton3D" index="1"]
transform = Transform3D(0.988103, -0.15379, 0.000888439, 0.000314816, -0.00375239, -0.999992, 0.153792, 0.988096, -0.00365969, -0.489565, 0.739608, 0.0961331)
transform = Transform3D(0.986897, -0.161326, 0.0026515, 0.000882647, -0.0110331, -0.999938, 0.161346, 0.986839, -0.0107466, -0.488958, 0.729389, 0.098426)
[node name="2H_Crossbow" parent="Geometry/Rogue/Rig/Skeleton3D" index="2"]
transform = Transform3D(0.988103, -0.15379, 0.000888439, 0.000314816, -0.00375239, -0.999992, 0.153792, 0.988096, -0.00365969, -0.489565, 0.739608, 0.0961331)
transform = Transform3D(0.986897, -0.161326, 0.0026515, 0.000882647, -0.0110331, -0.999938, 0.161346, 0.986839, -0.0107466, -0.488958, 0.729389, 0.098426)
[node name="Knife" parent="Geometry/Rogue/Rig/Skeleton3D" index="3"]
transform = Transform3D(-0.000888434, -0.15379, 0.988103, 0.999992, -0.00375224, 0.000314836, 0.00365954, 0.988096, 0.153792, -0.491065, 0.634942, 0.105985)
transform = Transform3D(-0.00265149, -0.161326, 0.986897, 0.999938, -0.011033, 0.000882668, 0.0107464, 0.986839, 0.161345, -0.490351, 0.624652, 0.107524)
[node name="Throwable" parent="Geometry/Rogue/Rig/Skeleton3D" index="4"]
transform = Transform3D(-0.000888418, -0.15379, 0.988103, 0.999992, -0.00375223, 0.000314822, 0.00365953, 0.988096, 0.153792, -0.518785, 0.634265, 0.284086)
transform = Transform3D(-0.00265147, -0.161326, 0.986897, 0.999938, -0.011033, 0.000882653, 0.0107464, 0.986839, 0.161345, -0.51943, 0.622664, 0.285398)
[node name="Rogue_Cape" parent="Geometry/Rogue/Rig/Skeleton3D" index="5"]
transform = Transform3D(0.996275, -5.14962e-09, 0.0862354, 5.13044e-09, 1, 4.44078e-10, -0.0862354, 1.47756e-15, 0.996275, -4.17227e-09, 1.19996, 1.19714e-15)
transform = Transform3D(0.996275, -5.14962e-09, 0.0862354, 5.13044e-09, 1, 4.44078e-10, -0.0862354, 1.47756e-15, 0.996275, -4.17227e-09, 1.17836, 1.19714e-15)
[node name="AnimationPlayer" type="AnimationPlayer" parent="Geometry"]
root_node = NodePath("../Rogue")

View File

@ -200,3 +200,4 @@ locale/translations_pot_files=PackedStringArray("res://dialogue/bridge_builder_m
3d_physics/layer_4="Weapon & Projectile"
3d_physics/layer_5="Actionable"
3d_physics/layer_6="Structure"
3d_physics/layer_7="Non Player Character"

File diff suppressed because one or more lines are too long