TinyAdventure/ai/tasks/navigate_to_location.gd

34 lines
1.0 KiB
GDScript
Raw Permalink 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)
2024-12-31 16:25:39 +01:00
if DebugSystem.debug_npc == agent_npc: DebugDraw3D.draw_arrow(agent.global_position, target_location, Color.CRIMSON, 0.1, true)
var distance_to_target:float = (agent_npc.global_position - target_location).length()
2024-12-31 16:27:57 +01:00
var target_reached:bool = agent_npc.is_navigation_target_reached()
var navigation_finished:bool = agent_npc.is_navigation_finished()
if target_reached or navigation_finished or distance_to_target < distance:
agent_npc.navigation_active = false
return SUCCESS
return RUNNING