TinyAdventure/ai/tasks/navigate_to_location.gd

29 lines
797 B
GDScript
Raw Normal View History

@tool
extends BTAction
@export var target_var: StringName = &"target_location"
@export var distance:float = 0.1
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 not agent_npc:
push_error("Error: agent must be a NonPlayerCharacter")
return FAILURE
agent_npc.navigate_to(target_location)
var distance_to_target:float = (agent_npc.global_position - target_location).length()
if agent_npc.is_navigation_target_reached() or distance_to_target < distance:
agent_npc.navigation_active = false
return SUCCESS
return RUNNING