TinyAdventure/ai/tasks/calc_distance_to_location.gd

20 lines
514 B
GDScript
Raw Normal View History

@tool
extends BTAction
@export var target_location_var: StringName = &"target_location"
@export var output_var: StringName = &"location_distance"
func _generate_name() -> String:
return "CalcDistanceToLocation \"%s\" -> %s" % [
target_location_var,
output_var
]
func _tick(_delta: float) -> Status:
var target_location:Vector3 = blackboard.get_var(target_location_var)
var distance:float = (target_location - agent.global_position).length()
blackboard.set_var(output_var, distance)
return SUCCESS