From f776779175e3d4d046a617fb1ffb6cc97f659788 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 14 Aug 2023 13:29:16 +0200 Subject: [PATCH] Update waypoints demo --- demo/ai/tasks/play_animation.gd | 46 -------------------------------- demo/ai/tasks/start_animation.gd | 31 --------------------- demo/ai/trees/waypoints.tres | 15 ++++++----- 3 files changed, 9 insertions(+), 83 deletions(-) delete mode 100644 demo/ai/tasks/play_animation.gd delete mode 100644 demo/ai/tasks/start_animation.gd diff --git a/demo/ai/tasks/play_animation.gd b/demo/ai/tasks/play_animation.gd deleted file mode 100644 index ca833da..0000000 --- a/demo/ai/tasks/play_animation.gd +++ /dev/null @@ -1,46 +0,0 @@ -#* -#* play_animation.gd -#* ============================================================================= -#* Copyright 2021-2023 Serhii Snitsaruk -#* -#* Use of this source code is governed by an MIT-style -#* license that can be found in the LICENSE file or at -#* https://opensource.org/licenses/MIT. -#* ============================================================================= -#* - -@tool -extends BTAction - -@export var animation_name: String -@export var animation_player: NodePath - -var _player: AnimationPlayer -var _finished: bool - - -func _generate_name() -> String: - return "PlayAnimation \"%s\"" % animation_name - - -func _setup() -> void: - _player = agent.get_node(animation_player) - - -func _enter() -> void: - if _player.has_animation(animation_name): - _finished = false - _player.play(animation_name) - _player.animation_finished.connect(_on_animation_finished, CONNECT_ONE_SHOT) - else: - _finished = true - - -func _tick(_delta: float) -> int: - if _finished: - return SUCCESS - return RUNNING - - -func _on_animation_finished(_anim): - _finished = true diff --git a/demo/ai/tasks/start_animation.gd b/demo/ai/tasks/start_animation.gd deleted file mode 100644 index a109ff1..0000000 --- a/demo/ai/tasks/start_animation.gd +++ /dev/null @@ -1,31 +0,0 @@ -#* -#* start_animation.gd -#* ============================================================================= -#* Copyright 2021-2023 Serhii Snitsaruk -#* -#* Use of this source code is governed by an MIT-style -#* license that can be found in the LICENSE file or at -#* https://opensource.org/licenses/MIT. -#* ============================================================================= -#* - -@tool -extends BTAction - -@export var animation_name: String -@export var animation_player: NodePath - -var _player: AnimationPlayer - - -func _generate_name() -> String: - return "StartAnimation \"%s\"" % animation_name - - -func _setup() -> void: - _player = agent.get_node(animation_player) - - -func _tick(p_delta: float) -> int: - _player.play(animation_name) - return SUCCESS diff --git a/demo/ai/trees/waypoints.tres b/demo/ai/trees/waypoints.tres index c056b64..ecabd99 100644 --- a/demo/ai/trees/waypoints.tres +++ b/demo/ai/trees/waypoints.tres @@ -1,7 +1,6 @@ [gd_resource type="BehaviorTree" load_steps=10 format=3 uid="uid://cjkqi41oagagd"] [ext_resource type="Script" path="res://ai/tasks/arrive_pos.gd" id="1_rhs33"] -[ext_resource type="Script" path="res://ai/tasks/play_animation.gd" id="2_dg0ss"] [sub_resource type="BTAction" id="BTAction_3xal7"] script = ExtResource("1_rhs33") @@ -9,16 +8,20 @@ target_position_var = "wp" speed_var = "speed" tolerance = 50.0 -[sub_resource type="BTAction" id="BTAction_yq1vl"] -script = ExtResource("2_dg0ss") -animation_name = "bounce" -animation_player = NodePath("AnimationPlayer") +[sub_resource type="BBNode" id="BBNode_0t2vk"] +resource_name = "AnimationPlayer" +saved_value = NodePath("AnimationPlayer") + +[sub_resource type="BTPlayAnimation" id="BTPlayAnimation_s01ov"] +await_completion = 1.0 +animation_player = SubResource("BBNode_0t2vk") +animation_name = &"bounce" [sub_resource type="BTWait" id="BTWait_qs55a"] duration = 0.1 [sub_resource type="BTSequence" id="BTSequence_a2ng0"] -children = [SubResource("BTAction_3xal7"), SubResource("BTAction_yq1vl"), SubResource("BTWait_qs55a")] +children = [SubResource("BTAction_3xal7"), SubResource("BTPlayAnimation_s01ov"), SubResource("BTWait_qs55a")] [sub_resource type="BTForEach" id="BTForEach_0cp04"] children = [SubResource("BTSequence_a2ng0")]