TinyAdventure/ai/tasks/navigate_to_location.gd

26 lines
657 B
GDScript
Raw Normal View History

@tool
extends BTAction
@export var target_var: StringName = &"target_location"
var target_location:Vector3 = Vector3.ZERO
func _generate_name() -> String:
return "NavigateTo \"%s\"" % [
LimboUtility.decorate_var(target_var)
]
func _tick(_delta: float) -> Status:
target_location = blackboard.get_var(target_var)
var agent_npc:NonPlayerCharacter = agent as NonPlayerCharacter
if agent_npc:
agent_npc.navigate_to(target_location)
var agent_node:Node3D = agent as Node3D
if agent_node:
var distance_to_target:float = (agent_node.global_position - target_location).length()
if distance_to_target < 0.1:
return SUCCESS
return RUNNING