2024-12-28 14:57:56 +01:00
|
|
|
@tool
|
|
|
|
extends BTAction
|
|
|
|
|
|
|
|
@export var target_var: StringName = &"target_location"
|
2024-12-29 11:18:25 +01:00
|
|
|
@export var distance:float = 0.1
|
2024-12-28 14:57:56 +01:00
|
|
|
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
|
2024-12-29 11:18:25 +01:00
|
|
|
if not agent_npc:
|
|
|
|
push_error("Error: agent must be a NonPlayerCharacter")
|
|
|
|
return FAILURE
|
|
|
|
|
|
|
|
agent_npc.navigate_to(target_location)
|
2024-12-28 14:57:56 +01:00
|
|
|
|
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)
|
|
|
|
|
2024-12-29 11:18:25 +01:00
|
|
|
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
|
2024-12-28 14:57:56 +01:00
|
|
|
|
|
|
|
return RUNNING
|