TinyAdventure/ai/tasks/navigate_to.gd

34 lines
881 B
GDScript
Raw Permalink Normal View History

@tool
extends BTAction
@export var target_var: StringName = &"target"
var target_node:Node3D = null
var current_target_name:String = ""
func _generate_name() -> String:
return "NavigateTo \"%s\"" % [
LimboUtility.decorate_var(target_var)
]
func _tick(_delta: float) -> Status:
target_node = blackboard.get_var(target_var)
if not is_instance_valid(target_node):
return FAILURE
if current_target_name != target_node.name:
current_target_name = target_node.name
print ("Next target: " + current_target_name)
var agent_npc:NonPlayerCharacter = agent as NonPlayerCharacter
if agent_npc:
agent_npc.navigate_to(target_node.global_position)
var agent_node:Node3D = agent as Node3D
if agent_node:
var distance_to_target:float = (agent.global_position - target_node.global_position).length()
if distance_to_target < 0.1:
return SUCCESS
return RUNNING