TinyAdventure/ai/tasks/find_path.gd

30 lines
773 B
GDScript
Raw Permalink Normal View History

2025-01-14 22:10:45 +01:00
@tool
extends BTAction
@export var path_name: String = ""
@export var navigation_path_var: StringName = &"navigation_path"
var _path:Path3D = null
func _generate_name() -> String:
return "FindPath(\"%s\") ➜ %s" % [
LimboUtility.decorate_var(path_name), LimboUtility.decorate_var(navigation_path_var)
]
func _tick(_delta: float) -> Status:
var _blackboard:Blackboard = blackboard
if not path_name.is_empty():
_path = agent.get_tree().root.find_child(path_name, true, false) as Path3D
if not is_instance_valid(_path):
_path = blackboard.get_var("patrol_path") as Path3D
if not is_instance_valid(_path):
push_error("Could not find path with name %s!" % path_name)
return FAILURE
blackboard.set_var(navigation_path_var, _path)
return SUCCESS