Adds enemies

This commit is contained in:
Michel 2025-02-01 22:51:01 +01:00
parent cf8ba8bacb
commit 76e5b1927f
324 changed files with 28447 additions and 106 deletions

View file

@ -0,0 +1,29 @@
[gd_resource type="BehaviorTree" load_steps=5 format=3 uid="uid://b1mfh8yad7rmw"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_ewfwq"]
var/speed/name = &"speed"
var/speed/type = 3
var/speed/value = 400.0
var/speed/hint = 1
var/speed/hint_string = "10,1000,10"
[sub_resource type="BBNode" id="BBNode_fq0jf"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_rsejo"]
animation_player = SubResource("BBNode_fq0jf")
animation_name = &"idle"
[sub_resource type="BTSequence" id="BTSequence_4bq32"]
children = [SubResource("BTPlayAnimation_rsejo")]
[resource]
description = "Welcome to the [b]LimboAI Tutorial[/b]!
Here, you'll learn how to use behavior trees to craft AI for your games. We'll start with the basics and gradually move to more advanced topics. Strap in for a quick and engaging introduction to behavior trees.
Press ➡ button in the top-right corner to proceed.
Press ⬅ button any time you want to go back to a previous chapter."
blackboard_plan = SubResource("BlackboardPlan_ewfwq")
root_task = SubResource("BTSequence_4bq32")

View file

@ -0,0 +1,45 @@
[gd_resource type="BehaviorTree" load_steps=9 format=3 uid="uid://b1i0xo0o676va"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_ewfwq"]
var/speed/name = &"speed"
var/speed/type = 3
var/speed/value = 400.0
var/speed/hint = 1
var/speed/hint_string = "10,1000,10"
var/flank_speed/name = &"flank_speed"
var/flank_speed/type = 3
var/flank_speed/value = 600.0
var/flank_speed/hint = 1
var/flank_speed/hint_string = "10,1000,10"
[sub_resource type="BBNode" id="BBNode_wu06u"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_dubaq"]
animation_player = SubResource("BBNode_wu06u")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_meli1"]
duration = 5.0
[sub_resource type="BBNode" id="BBNode_mgehh"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_0fqno"]
animation_player = SubResource("BBNode_mgehh")
animation_name = &"dance"
[sub_resource type="BTWait" id="BTWait_m3h4o"]
duration = 5.0
[sub_resource type="BTSequence" id="BTSequence_rbfdh"]
children = [SubResource("BTPlayAnimation_dubaq"), SubResource("BTWait_meli1"), SubResource("BTPlayAnimation_0fqno"), SubResource("BTWait_m3h4o")]
[resource]
description = "Behavior trees are designed to simplify the creation of responsive and modular behaviors for games. They consist of tasks that represent specific actions or decision-making rules. Tasks can be broadly categorized into two groups: control tasks and leaf tasks. [b]Control tasks[/b] dictate the execution flow within the tree, while [b]leaf tasks[/b] represent specific actions to perform (such as moving or attacking) or conditions that need to be checked. Typically, it's the leaf tasks that perform the actual work in behavior trees.
A behavior tree is usually processed each frame (physics frame by default). It is traversed from top to bottom, with the control tasks determining the control flow. Each task has a [color=cyan]_tick[/color] method, which performs the task's work and returns a status indicating its progress: [SUCCESS], [FAILURE], or [RUNNING]. [SUCCESS] and [FAILURE] indicate the outcome of finished work, while [RUNNING] status is returned when a task requires more than one tick to complete its job. These statuses determine how the tree progresses, with the [RUNNING] status usually meaning that the tree will continue execution during the next frame."
blackboard_plan = SubResource("BlackboardPlan_ewfwq")
root_task = SubResource("BTSequence_rbfdh")

View file

@ -0,0 +1,97 @@
[gd_resource type="BehaviorTree" load_steps=24 format=3 uid="uid://cb0ybf24ahnc3"]
[ext_resource type="Script" path="res://demo/ai/tasks/select_random_nearby_pos.gd" id="1_as4cg"]
[ext_resource type="Script" path="res://demo/ai/tasks/arrive_pos.gd" id="2_dlpnp"]
[ext_resource type="Script" path="res://demo/ai/tasks/get_first_in_group.gd" id="3_uv18s"]
[ext_resource type="Script" path="res://demo/ai/tasks/in_range.gd" id="4_k3g8t"]
[ext_resource type="Script" path="res://demo/ai/tasks/face_target.gd" id="5_thvy5"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_ewfwq"]
var/speed/name = &"speed"
var/speed/type = 3
var/speed/value = 400.0
var/speed/hint = 1
var/speed/hint_string = "10,1000,10"
[sub_resource type="BBNode" id="BBNode_20ku0"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_57u80"]
animation_player = SubResource("BBNode_20ku0")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_11xvc"]
script = ExtResource("1_as4cg")
range_min = 300.0
range_max = 500.0
position_var = &"pos"
[sub_resource type="BTAction" id="BTAction_tdkpj"]
script = ExtResource("2_dlpnp")
target_position_var = &"pos"
speed_var = &"speed"
tolerance = 50.0
avoid_var = &""
[sub_resource type="BTSequence" id="BTSequence_echit"]
children = [SubResource("BTPlayAnimation_57u80"), SubResource("BTAction_11xvc"), SubResource("BTAction_tdkpj")]
[sub_resource type="BTProbability" id="BTProbability_g0ol3"]
children = [SubResource("BTSequence_echit")]
[sub_resource type="BTAction" id="BTAction_124bm"]
script = ExtResource("3_uv18s")
group = &"player"
output_var = &"target"
[sub_resource type="BTCondition" id="BTCondition_n25o8"]
script = ExtResource("4_k3g8t")
distance_min = 0.0
distance_max = 200.0
target_var = &"target"
[sub_resource type="BTAction" id="BTAction_1hfgr"]
script = ExtResource("5_thvy5")
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_ilr2h"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_mrsu3"]
animation_player = SubResource("BBNode_ilr2h")
animation_name = &"attack_1"
[sub_resource type="BTSequence" id="BTSequence_5vug3"]
children = [SubResource("BTAction_124bm"), SubResource("BTCondition_n25o8"), SubResource("BTAction_1hfgr"), SubResource("BTPlayAnimation_mrsu3")]
[sub_resource type="BBNode" id="BBNode_fq0jf"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_rsejo"]
animation_player = SubResource("BBNode_fq0jf")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_dl31p"]
duration = 2.0
[sub_resource type="BTSequence" id="BTSequence_vx4uy"]
children = [SubResource("BTPlayAnimation_rsejo"), SubResource("BTWait_dl31p")]
[sub_resource type="BTSelector" id="BTSelector_tdpek"]
children = [SubResource("BTProbability_g0ol3"), SubResource("BTSequence_5vug3"), SubResource("BTSequence_vx4uy")]
[resource]
description = "There are four types of tasks:
[ul][act]Actions[/act] are leaf tasks that perform the actual work.[/ul]
[ul][con]Conditions[/con] are leaf tasks that conduct various checks.[/ul]
[ul][comp]Composites[/comp] can have one or more child tasks, and dictate the execution flow of their children.[/ul]
[ul][dec]Decorators[/dec] can only have a single child and they change how their child task operates.[/ul]
Let's take a look into actions first. [act]Actions[/act] are responsible for most of the work and often change the game state in a significant manner. For instance, [act]PlayAnimation[/act] instructs the AnimationPlayer to start a specified animation, with the option to wait for its completion. On the other hand, the [act]Wait[/act] task simply pauses for a set duration before returning [SUCCESS].
Next, we'll explore the core composite tasks, such as [comp]Sequence[/comp] and [comp]Selector[/comp]. These are among the most crucial composites that you should know about."
blackboard_plan = SubResource("BlackboardPlan_ewfwq")
root_task = SubResource("BTSelector_tdpek")

View file

@ -0,0 +1,62 @@
[gd_resource type="BehaviorTree" load_steps=15 format=3 uid="uid://dln8ywvtqedt7"]
[ext_resource type="Script" path="res://demo/ai/tasks/select_random_nearby_pos.gd" id="1_gk66j"]
[ext_resource type="Script" path="res://demo/ai/tasks/arrive_pos.gd" id="2_v5eou"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_ewfwq"]
var/speed/name = &"speed"
var/speed/type = 3
var/speed/value = 400.0
var/speed/hint = 1
var/speed/hint_string = "10,1000,10"
[sub_resource type="BBNode" id="BBNode_fq0jf"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_rsejo"]
animation_player = SubResource("BBNode_fq0jf")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_dl31p"]
duration = 3.0
[sub_resource type="BBNode" id="BBNode_6d0yy"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_wsspf"]
animation_player = SubResource("BBNode_6d0yy")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_fc1oo"]
script = ExtResource("1_gk66j")
range_min = 300.0
range_max = 500.0
position_var = &"pos"
[sub_resource type="BTAction" id="BTAction_djl5v"]
script = ExtResource("2_v5eou")
target_position_var = &"pos"
speed_var = &"speed"
tolerance = 50.0
avoid_var = &""
[sub_resource type="BTFail" id="BTFail_i2f36"]
[sub_resource type="BTComment" id="BTComment_4i06i"]
custom_name = "👇️ Sequence is never going to reach this task, because it fails at the previous step."
[sub_resource type="BTWait" id="BTWait_yxpnx"]
duration = 888.0
[sub_resource type="BTSequence" id="BTSequence_vx4uy"]
children = [SubResource("BTPlayAnimation_rsejo"), SubResource("BTWait_dl31p"), SubResource("BTPlayAnimation_wsspf"), SubResource("BTAction_fc1oo"), SubResource("BTAction_djl5v"), SubResource("BTFail_i2f36"), SubResource("BTComment_4i06i"), SubResource("BTWait_yxpnx")]
[resource]
description = "The [comp]Sequence[/comp] is one of the core composite tasks. It executes its child tasks sequentially, from first to last, until one of them returns [FAILURE], or all of them result in [SUCCESS]. In other words, if any child task results in [FAILURE], the Sequence execution will be aborted, and the Sequence itself will return [FAILURE].
In our example, you can observe a simple [comp]Sequence[/comp] in action. Notice how it fails when it reaches the [act]Fail[/act] action and never proceeds to the [act]Wait 888 sec[/act] action afterward. By the way, the simple [act]Fail[/act] task is quite useful for troubleshooting. Its sole function is to return [FAILURE].
"
blackboard_plan = SubResource("BlackboardPlan_ewfwq")
root_task = SubResource("BTSequence_vx4uy")

View file

@ -0,0 +1,108 @@
[gd_resource type="BehaviorTree" load_steps=26 format=3 uid="uid://bf4r652fv5kwi"]
[ext_resource type="Script" path="res://demo/ai/tasks/get_first_in_group.gd" id="1_3ed74"]
[ext_resource type="Script" path="res://demo/ai/tasks/select_random_nearby_pos.gd" id="1_rvh1c"]
[ext_resource type="Script" path="res://demo/ai/tasks/in_range.gd" id="2_jfsyt"]
[ext_resource type="Script" path="res://demo/ai/tasks/pursue.gd" id="2_nnswb"]
[ext_resource type="Script" path="res://demo/ai/tasks/arrive_pos.gd" id="2_t62a0"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_ewfwq"]
var/speed/name = &"speed"
var/speed/type = 3
var/speed/value = 400.0
var/speed/hint = 1
var/speed/hint_string = "10,1000,10"
[sub_resource type="BTCondition" id="BTCondition_x0uu7"]
script = ExtResource("2_jfsyt")
distance_min = 0.0
distance_max = 200.0
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_icf24"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_iiei3"]
animation_player = SubResource("BBNode_icf24")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_824oc"]
script = ExtResource("1_rvh1c")
range_min = 700.0
range_max = 800.0
position_var = &"pos"
[sub_resource type="BTAction" id="BTAction_y1you"]
script = ExtResource("2_t62a0")
target_position_var = &"pos"
speed_var = &"speed"
tolerance = 50.0
avoid_var = &""
[sub_resource type="BBNode" id="BBNode_ayt56"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_l1tdg"]
animation_player = SubResource("BBNode_ayt56")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_hh8ys"]
duration = 3.0
[sub_resource type="BTSequence" id="BTSequence_cgwor"]
children = [SubResource("BTCondition_x0uu7"), SubResource("BTPlayAnimation_iiei3"), SubResource("BTAction_824oc"), SubResource("BTAction_y1you"), SubResource("BTPlayAnimation_l1tdg"), SubResource("BTWait_hh8ys")]
[sub_resource type="BTCondition" id="BTCondition_d6aub"]
script = ExtResource("2_jfsyt")
distance_min = 200.0
distance_max = 10000.0
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_6d0yy"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_wsspf"]
animation_player = SubResource("BBNode_6d0yy")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_wc11r"]
script = ExtResource("2_nnswb")
target_var = &"target"
speed_var = &"speed"
approach_distance = 100.0
[sub_resource type="BBNode" id="BBNode_aw5jj"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_3aihc"]
animation_player = SubResource("BBNode_aw5jj")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_1o163"]
duration = 3.0
[sub_resource type="BTSequence" id="BTSequence_vx4uy"]
children = [SubResource("BTCondition_d6aub"), SubResource("BTPlayAnimation_wsspf"), SubResource("BTAction_wc11r"), SubResource("BTPlayAnimation_3aihc"), SubResource("BTWait_1o163")]
[sub_resource type="BTAction" id="BTAction_2murg"]
script = ExtResource("1_3ed74")
group = &"player"
output_var = &"target"
[sub_resource type="BTSelector" id="BTSelector_ddhoo"]
children = [SubResource("BTSequence_cgwor"), SubResource("BTSequence_vx4uy"), SubResource("BTAction_2murg")]
[resource]
description = "The [comp]Selector[/comp] is another essential composite task. It executes its child tasks sequentially, from first to last, until one of them returns [SUCCESS] or all of them result in [FAILURE]. In other words, when a child task results in [FAILURE], it moves on to the next one until it finds the one that returns [SUCCESS]. Once a child task results in [SUCCESS], the Selector stops and also returns [SUCCESS].
To understand the [comp]Selector[/comp], it helps to see it as the opposite of the [comp]Sequence[/comp]. While the Sequence continues iterating over children as long as they return [SUCCESS], the Selector does the same but as long as they return [FAILURE]. The purpose of the Selector is to find a child that succeeds. It's often useful to place higher priority tasks at the top so that the Selector attempts them first.
[comp]Selector[/comp] is frequently used with [comp]Sequence[/comp] and [con]Condition[/con] tasks to control the behavior tree's flow. A condition task would prevent a Sequence from proceeding if it evaluates to [FAILURE], and thus the Selector would try the next child.
In our example, the [con]InRange[/con] condition checks how far Junior is from the target. When Junior is farther than 200 pixels from the target, he'll attempt to approach it. If he is closer than 200 pixels from the target, he would try to walk away. Thanks to the Selector, only one of these behaviors will be performed at a time, based on the result of the [con]InRange[/con] check. Junior seems to have a dilemma — unable to decide whether to stay or go."
blackboard_plan = SubResource("BlackboardPlan_ewfwq")
root_task = SubResource("BTSelector_ddhoo")

View file

@ -0,0 +1,136 @@
[gd_resource type="BehaviorTree" load_steps=34 format=3 uid="uid://beiki511huxb8"]
[ext_resource type="Script" path="res://demo/ai/tasks/get_first_in_group.gd" id="1_3xoj7"]
[ext_resource type="Script" path="res://demo/ai/tasks/in_range.gd" id="2_08b67"]
[ext_resource type="Script" path="res://demo/ai/tasks/face_target.gd" id="3_orhnl"]
[ext_resource type="Script" path="res://demo/ai/tasks/select_random_nearby_pos.gd" id="4_oyght"]
[ext_resource type="Script" path="res://demo/ai/tasks/arrive_pos.gd" id="5_5o1gy"]
[ext_resource type="Script" path="res://demo/ai/tasks/pursue.gd" id="6_rpn40"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_ewfwq"]
var/speed/name = &"speed"
var/speed/type = 3
var/speed/value = 400.0
var/speed/hint = 1
var/speed/hint_string = "10,1000,10"
[sub_resource type="BTAction" id="BTAction_2murg"]
script = ExtResource("1_3xoj7")
group = &"player"
output_var = &"target"
[sub_resource type="BTRunLimit" id="BTRunLimit_60b8b"]
children = [SubResource("BTAction_2murg")]
[sub_resource type="BTCondition" id="BTCondition_m15aa"]
script = ExtResource("2_08b67")
distance_min = 0.0
distance_max = 200.0
target_var = &"target"
[sub_resource type="BTAction" id="BTAction_oc76s"]
script = ExtResource("3_orhnl")
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_6d0yy"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_wsspf"]
await_completion = 5.0
animation_player = SubResource("BBNode_6d0yy")
animation_name = &"attack_1"
[sub_resource type="BTSequence" id="BTSequence_e0f8v"]
children = [SubResource("BTCondition_m15aa"), SubResource("BTAction_oc76s"), SubResource("BTPlayAnimation_wsspf")]
[sub_resource type="BTCooldown" id="BTCooldown_3tvjt"]
children = [SubResource("BTSequence_e0f8v")]
duration = 5.0
[sub_resource type="BTCondition" id="BTCondition_x0uu7"]
script = ExtResource("2_08b67")
distance_min = 0.0
distance_max = 200.0
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_icf24"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_iiei3"]
animation_player = SubResource("BBNode_icf24")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_824oc"]
script = ExtResource("4_oyght")
range_min = 700.0
range_max = 800.0
position_var = &"pos"
[sub_resource type="BTAction" id="BTAction_y1you"]
script = ExtResource("5_5o1gy")
target_position_var = &"pos"
speed_var = &"speed"
tolerance = 50.0
avoid_var = &""
[sub_resource type="BBNode" id="BBNode_ayt56"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_l1tdg"]
animation_player = SubResource("BBNode_ayt56")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_hh8ys"]
duration = 3.0
[sub_resource type="BTSequence" id="BTSequence_cgwor"]
children = [SubResource("BTCondition_x0uu7"), SubResource("BTPlayAnimation_iiei3"), SubResource("BTAction_824oc"), SubResource("BTAction_y1you"), SubResource("BTPlayAnimation_l1tdg"), SubResource("BTWait_hh8ys")]
[sub_resource type="BTCondition" id="BTCondition_d6aub"]
script = ExtResource("2_08b67")
distance_min = 200.0
distance_max = 10000.0
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_rpwld"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_dug2k"]
animation_player = SubResource("BBNode_rpwld")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_wc11r"]
script = ExtResource("6_rpn40")
target_var = &"target"
speed_var = &"speed"
approach_distance = 100.0
[sub_resource type="BBNode" id="BBNode_aw5jj"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_3aihc"]
animation_player = SubResource("BBNode_aw5jj")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_1o163"]
duration = 0.5
[sub_resource type="BTSequence" id="BTSequence_vx4uy"]
children = [SubResource("BTCondition_d6aub"), SubResource("BTPlayAnimation_dug2k"), SubResource("BTAction_wc11r"), SubResource("BTPlayAnimation_3aihc"), SubResource("BTWait_1o163")]
[sub_resource type="BTSelector" id="BTSelector_ddhoo"]
children = [SubResource("BTRunLimit_60b8b"), SubResource("BTCooldown_3tvjt"), SubResource("BTSequence_cgwor"), SubResource("BTSequence_vx4uy")]
[resource]
description = "Let's improve our previous behavior, and take the opportunity to discuss [dec]Decorators[/dec]. As mentioned earlier, decorators are control tasks that should only have a single child. Typically, a decorator either alters how its child operates or modifies its return status. They are often a useful tool for introducing variance into behaviors that otherwise lack it.
In our example, we utilize the [dec]RunLimit[/dec] decorator to restrict its child from running more than once. After executing the first time, the child will never receive another tick. This is quite handy for all sorts of setup logic!
Now, let's examine another decorator we use here - the [dec]Cooldown[/dec]. This decorator executes its child task only if the specified duration time has passed since the previous execution of the child task. The first time the attack sequence results in [SUCCESS], it triggers the cooldown, preventing the [comp]Sequence[/comp] from being executed for the next 5 seconds. During this period, the Cooldown returns [FAILURE] until the specified duration time elapses. It's important to note that it only counts executions that finished with [SUCCESS]. This means that [con]InRange[/con] can be utilized here without triggering the Cooldown!"
blackboard_plan = SubResource("BlackboardPlan_ewfwq")
root_task = SubResource("BTSelector_ddhoo")

View file

@ -0,0 +1,143 @@
[gd_resource type="BehaviorTree" load_steps=36 format=3 uid="uid://tep50j4d6kgp"]
[ext_resource type="Script" path="res://demo/ai/tasks/get_first_in_group.gd" id="1_f605f"]
[ext_resource type="Script" path="res://demo/ai/tasks/in_range.gd" id="2_mj1cj"]
[ext_resource type="Script" path="res://demo/ai/tasks/face_target.gd" id="3_86p0r"]
[ext_resource type="Script" path="res://demo/ai/tasks/back_away.gd" id="4_u0vk1"]
[ext_resource type="Script" path="res://demo/ai/tasks/pursue.gd" id="6_1yikm"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_ewfwq"]
var/speed/name = &"speed"
var/speed/type = 3
var/speed/value = 400.0
var/speed/hint = 1
var/speed/hint_string = "10,1000,10"
[sub_resource type="BTAction" id="BTAction_2murg"]
script = ExtResource("1_f605f")
group = &"player"
output_var = &"target"
[sub_resource type="BTRunLimit" id="BTRunLimit_60b8b"]
children = [SubResource("BTAction_2murg")]
[sub_resource type="BTCondition" id="BTCondition_m15aa"]
script = ExtResource("2_mj1cj")
distance_min = 0.0
distance_max = 200.0
target_var = &"target"
[sub_resource type="BTAction" id="BTAction_oc76s"]
script = ExtResource("3_86p0r")
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_6d0yy"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_wsspf"]
await_completion = 5.0
animation_player = SubResource("BBNode_6d0yy")
animation_name = &"attack_1"
[sub_resource type="BBNode" id="BBNode_w45kn"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_d2lad"]
await_completion = 5.0
animation_player = SubResource("BBNode_w45kn")
animation_name = &"attack_2"
[sub_resource type="BTSequence" id="BTSequence_e0f8v"]
children = [SubResource("BTCondition_m15aa"), SubResource("BTAction_oc76s"), SubResource("BTPlayAnimation_wsspf"), SubResource("BTPlayAnimation_d2lad")]
[sub_resource type="BTCooldown" id="BTCooldown_3tvjt"]
children = [SubResource("BTSequence_e0f8v")]
duration = 5.0
[sub_resource type="BTCondition" id="BTCondition_x0uu7"]
script = ExtResource("2_mj1cj")
distance_min = 0.0
distance_max = 200.0
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_wksgd"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_umlwj"]
animation_player = SubResource("BBNode_wksgd")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_6q0k4"]
script = ExtResource("4_u0vk1")
speed_var = &"speed"
max_angle_deviation = 0.7
[sub_resource type="BTTimeLimit" id="BTTimeLimit_6eii7"]
children = [SubResource("BTAction_6q0k4")]
time_limit = 2.0
[sub_resource type="BTAlwaysSucceed" id="BTAlwaysSucceed_ieord"]
children = [SubResource("BTTimeLimit_6eii7")]
[sub_resource type="BBNode" id="BBNode_ayt56"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_l1tdg"]
animation_player = SubResource("BBNode_ayt56")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_hh8ys"]
duration = 3.0
[sub_resource type="BTSequence" id="BTSequence_cgwor"]
children = [SubResource("BTCondition_x0uu7"), SubResource("BTPlayAnimation_umlwj"), SubResource("BTAlwaysSucceed_ieord"), SubResource("BTPlayAnimation_l1tdg"), SubResource("BTWait_hh8ys")]
[sub_resource type="BTCondition" id="BTCondition_d6aub"]
script = ExtResource("2_mj1cj")
distance_min = 200.0
distance_max = 10000.0
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_rpwld"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_dug2k"]
animation_player = SubResource("BBNode_rpwld")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_wc11r"]
script = ExtResource("6_1yikm")
target_var = &"target"
speed_var = &"speed"
approach_distance = 100.0
[sub_resource type="BBNode" id="BBNode_aw5jj"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_3aihc"]
animation_player = SubResource("BBNode_aw5jj")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_1o163"]
duration = 0.5
[sub_resource type="BTSequence" id="BTSequence_vx4uy"]
children = [SubResource("BTCondition_d6aub"), SubResource("BTPlayAnimation_dug2k"), SubResource("BTAction_wc11r"), SubResource("BTPlayAnimation_3aihc"), SubResource("BTWait_1o163")]
[sub_resource type="BTSelector" id="BTSelector_ddhoo"]
children = [SubResource("BTRunLimit_60b8b"), SubResource("BTCooldown_3tvjt"), SubResource("BTSequence_cgwor"), SubResource("BTSequence_vx4uy")]
[resource]
description = "Let's explore some other [dec]Decorators[/dec]. Here's a slightly improved version of the previous behavior. We incorporate the [dec]TimeLimit[/dec] decorator with the [act]Back Away[/act] action to achieve a similar effect as before (walking away from the target). The TimeLimit decorator ensures that the child task does not take too long to finish its work. If the time runs out, the task's execution will be aborted, and TimeLimit will return [FAILURE].
Another useful decorator is [dec]AlwaysSucceed[/dec], which converts any [FAILURE] returned by its child into [SUCCESS]. We use this decorator here because TimeLimit may result in [FAILURE], but we still want the [comp]Sequence[/comp] to continue. Also, there are similar decorators such as [dec]AlwaysFail[/dec] and [dec]Invert[/dec], which you can use in your behavior trees as needed.
We also add a second attack, so that Junior feels more badass now. We've got a little hit-and-run behavior going on here!"
blackboard_plan = SubResource("BlackboardPlan_ewfwq")
root_task = SubResource("BTSelector_ddhoo")

View file

@ -0,0 +1,204 @@
[gd_resource type="BehaviorTree" load_steps=52 format=3 uid="uid://dp0cglcytwcj5"]
[ext_resource type="Script" path="res://demo/ai/tasks/get_first_in_group.gd" id="1_o5ahw"]
[ext_resource type="Script" path="res://demo/ai/tasks/select_flanking_pos.gd" id="2_er25a"]
[ext_resource type="Script" path="res://demo/ai/tasks/arrive_pos.gd" id="3_ed1xo"]
[ext_resource type="Script" path="res://demo/ai/tasks/face_target.gd" id="4_128ei"]
[ext_resource type="Script" path="res://demo/ai/tasks/in_range.gd" id="5_er18b"]
[ext_resource type="Script" path="res://demo/ai/tasks/back_away.gd" id="6_1urfq"]
[ext_resource type="Script" path="res://demo/ai/tasks/pursue.gd" id="7_ekws5"]
[sub_resource type="BlackboardPlan" id="BlackboardPlan_ewfwq"]
var/speed/name = &"speed"
var/speed/type = 3
var/speed/value = 400.0
var/speed/hint = 1
var/speed/hint_string = "10,1000,10"
[sub_resource type="BTAction" id="BTAction_2murg"]
script = ExtResource("1_o5ahw")
group = &"player"
output_var = &"target"
[sub_resource type="BTRunLimit" id="BTRunLimit_60b8b"]
children = [SubResource("BTAction_2murg")]
[sub_resource type="BTCondition" id="BTCondition_m15aa"]
script = ExtResource("5_er18b")
distance_min = 0.0
distance_max = 200.0
target_var = &"target"
[sub_resource type="BTAction" id="BTAction_oc76s"]
script = ExtResource("4_128ei")
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_6d0yy"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_wsspf"]
await_completion = 5.0
animation_player = SubResource("BBNode_6d0yy")
animation_name = &"attack_1"
[sub_resource type="BBNode" id="BBNode_w45kn"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_d2lad"]
await_completion = 5.0
animation_player = SubResource("BBNode_w45kn")
animation_name = &"attack_2"
[sub_resource type="BTSequence" id="BTSequence_e0f8v"]
children = [SubResource("BTCondition_m15aa"), SubResource("BTAction_oc76s"), SubResource("BTPlayAnimation_wsspf"), SubResource("BTPlayAnimation_d2lad")]
[sub_resource type="BTCooldown" id="BTCooldown_3tvjt"]
children = [SubResource("BTSequence_e0f8v")]
duration = 5.0
[sub_resource type="BTCondition" id="BTCondition_x0uu7"]
script = ExtResource("5_er18b")
distance_min = 0.0
distance_max = 200.0
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_wksgd"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_umlwj"]
animation_player = SubResource("BBNode_wksgd")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_6q0k4"]
script = ExtResource("6_1urfq")
speed_var = &"speed"
max_angle_deviation = 0.7
[sub_resource type="BTTimeLimit" id="BTTimeLimit_6eii7"]
children = [SubResource("BTAction_6q0k4")]
time_limit = 2.0
[sub_resource type="BTAlwaysSucceed" id="BTAlwaysSucceed_ieord"]
children = [SubResource("BTTimeLimit_6eii7")]
[sub_resource type="BBNode" id="BBNode_ayt56"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_l1tdg"]
animation_player = SubResource("BBNode_ayt56")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_hh8ys"]
duration = 3.0
[sub_resource type="BTSequence" id="BTSequence_cgwor"]
children = [SubResource("BTCondition_x0uu7"), SubResource("BTPlayAnimation_umlwj"), SubResource("BTAlwaysSucceed_ieord"), SubResource("BTPlayAnimation_l1tdg"), SubResource("BTWait_hh8ys")]
[sub_resource type="BTAction" id="BTAction_n0rxm"]
script = ExtResource("2_er25a")
target_var = &"target"
flank_side = 0
range_min = 400
range_max = 500
position_var = &"pos"
[sub_resource type="BBNode" id="BBNode_icf24"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_iiei3"]
animation_player = SubResource("BBNode_icf24")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_g2up4"]
script = ExtResource("3_ed1xo")
target_position_var = &"pos"
speed_var = &"speed"
tolerance = 50.0
avoid_var = &""
[sub_resource type="BTAction" id="BTAction_d5lkr"]
script = ExtResource("4_128ei")
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_h4k80"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_40yja"]
animation_player = SubResource("BBNode_h4k80")
animation_name = &"throw_prepare"
[sub_resource type="BTWait" id="BTWait_2dc1v"]
[sub_resource type="BBNode" id="BBNode_slipn"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_qnpjq"]
await_completion = 5.0
animation_player = SubResource("BBNode_slipn")
animation_name = &"throw"
[sub_resource type="BBNode" id="BBNode_qaqnn"]
resource_name = "."
saved_value = NodePath(".")
[sub_resource type="BTCallMethod" id="BTCallMethod_yd0fn"]
node = SubResource("BBNode_qaqnn")
method = &"throw_ninja_star"
[sub_resource type="BTSequence" id="BTSequence_ws7nq"]
children = [SubResource("BTAction_n0rxm"), SubResource("BTPlayAnimation_iiei3"), SubResource("BTAction_g2up4"), SubResource("BTAction_d5lkr"), SubResource("BTPlayAnimation_40yja"), SubResource("BTWait_2dc1v"), SubResource("BTPlayAnimation_qnpjq"), SubResource("BTCallMethod_yd0fn")]
[sub_resource type="BTProbability" id="BTProbability_omklt"]
children = [SubResource("BTSequence_ws7nq")]
run_chance = 0.25
[sub_resource type="BTCondition" id="BTCondition_d6aub"]
script = ExtResource("5_er18b")
distance_min = 200.0
distance_max = 10000.0
target_var = &"target"
[sub_resource type="BBNode" id="BBNode_rpwld"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_dug2k"]
animation_player = SubResource("BBNode_rpwld")
animation_name = &"walk"
[sub_resource type="BTAction" id="BTAction_wc11r"]
script = ExtResource("7_ekws5")
target_var = &"target"
speed_var = &"speed"
approach_distance = 100.0
[sub_resource type="BBNode" id="BBNode_aw5jj"]
resource_name = "AnimationPlayer"
saved_value = NodePath("AnimationPlayer")
[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_3aihc"]
animation_player = SubResource("BBNode_aw5jj")
animation_name = &"idle"
[sub_resource type="BTWait" id="BTWait_1o163"]
duration = 0.5
[sub_resource type="BTSequence" id="BTSequence_vx4uy"]
children = [SubResource("BTCondition_d6aub"), SubResource("BTPlayAnimation_dug2k"), SubResource("BTAction_wc11r"), SubResource("BTPlayAnimation_3aihc"), SubResource("BTWait_1o163")]
[sub_resource type="BTSelector" id="BTSelector_ddhoo"]
children = [SubResource("BTRunLimit_60b8b"), SubResource("BTCooldown_3tvjt"), SubResource("BTSequence_cgwor"), SubResource("BTProbability_omklt"), SubResource("BTSequence_vx4uy")]
[resource]
description = "And for the final touch, we've added throwing ninja stars to our previous behavior. The [dec]Probability[/dec] decorator adds a little variance so that we don't throw ninja stars all the time. This decorator executes its child task with a certain probability, so when it's not 100%, sometimes it will return [FAILURE] instead. Some of the work in this [comp]Sequence[/comp] is done by actions you've seen already, and the [act]CallMethod[/act] action invokes the [color=cyan]throw_ninja_star[/color] method on the agent node. By the way, the agent is always the owner of the BTPlayer node, which executes this behavior tree.
This concludes our tutorial. Hopefully, this little endeavor has been useful to you. You can learn more by reading the [b]Online Documentation[/b], which covers topics like creating your own tasks. Also, check out the [b]Showcase[/b], which presents behaviors of agents made for this little demo. Simply click \"End Tutorial\" to return to the [b]Showcase[/b]."
blackboard_plan = SubResource("BlackboardPlan_ewfwq")
root_task = SubResource("BTSelector_ddhoo")