Improved behaviour debugging.

main
Martin Felis 2024-12-31 16:25:39 +01:00
parent c7fd440888
commit fb30275324
7 changed files with 29 additions and 43 deletions

View File

@ -21,6 +21,8 @@ func _tick(delta: float) -> Status:
update_look_direction(delta) update_look_direction(delta)
if DebugSystem.debug_npc == _agent_npc: DebugDraw3D.draw_arrow(_agent_npc.global_position, target_position, Color.CRIMSON, 0.1, true)
if absf(_target_look_angle - _current_look_angle) < deg_to_rad(5): if absf(_target_look_angle - _current_look_angle) < deg_to_rad(5):
return SUCCESS return SUCCESS
@ -41,8 +43,6 @@ func update_look_direction(delta:float) -> void:
_target_look_angle = _target_look_direction.signed_angle_to(Vector3.BACK, Vector3.UP) _target_look_angle = _target_look_direction.signed_angle_to(Vector3.BACK, Vector3.UP)
#if _agent_npc and _agent_npc.get_path() == blackboard.get_var("debug_npc_path"): breakpoint
_current_look_angle = _look_angle_damper.calc(_current_look_angle, _target_look_angle, delta) _current_look_angle = _look_angle_damper.calc(_current_look_angle, _target_look_angle, delta)
clamp_current_look_angle() clamp_current_look_angle()

View File

@ -20,6 +20,8 @@ func _tick(_delta: float) -> Status:
agent_npc.navigate_to(target_location) agent_npc.navigate_to(target_location)
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() var distance_to_target:float = (agent_npc.global_position - target_location).length()
if agent_npc.is_navigation_target_reached() or distance_to_target < distance: if agent_npc.is_navigation_target_reached() or distance_to_target < distance:
agent_npc.navigation_active = false agent_npc.navigation_active = false

View File

@ -16,7 +16,7 @@ var/debug_npc_path/hint_string = ""
script = ExtResource("1_5wpmm") script = ExtResource("1_5wpmm")
radius = 3.0 radius = 3.0
output_var = &"target_location" output_var = &"target_location"
navigatable_target = false navigatable_target = true
stay_in_radius = true stay_in_radius = true
[sub_resource type="BTAction" id="BTAction_lschq"] [sub_resource type="BTAction" id="BTAction_lschq"]

View File

@ -61,6 +61,13 @@ func _ready() -> void:
func _physics_process(_delta: float) -> void: func _physics_process(_delta: float) -> void:
if navigation_active: if navigation_active:
var next_position:Vector3 = navigation_agent.get_next_path_position() var next_position:Vector3 = navigation_agent.get_next_path_position()
var current_path:PackedVector3Array = navigation_agent.get_current_navigation_path()
var path_length:float = 0
for i in range(1, current_path.size()):
path_length = path_length + (current_path[i] - current_path[i - 1]).length()
if DebugSystem.debug_npc == self: DebugDraw3D.draw_point_path(current_path, DebugDraw3D.POINT_TYPE_SPHERE, 0.02)
if is_nan(next_position.length()): if is_nan(next_position.length()):
breakpoint breakpoint

View File

@ -23,6 +23,12 @@ config/icon="res://icon.svg"
DialogueManager="*res://addons/dialogue_manager/dialogue_manager.gd" DialogueManager="*res://addons/dialogue_manager/dialogue_manager.gd"
InteractionSystem="*res://systems/InteractionSystem.gd" InteractionSystem="*res://systems/InteractionSystem.gd"
DebugSystem="*res://systems/DebugSystem.gd"
[debug_draw_3d]
settings/updates/check_for_updates=false
settings/3d/volumetric_defaults/thickness=0.01
[dialogue_manager] [dialogue_manager]

5
systems/DebugSystem.gd Normal file
View File

@ -0,0 +1,5 @@
extends Node
var player:Player = null
var debug_node:Node = null
var debug_npc:NonPlayerCharacter = null

View File

@ -38,55 +38,21 @@ func update_npc_option_button() -> void:
npc_option_button.add_item(node_name) npc_option_button.add_item(node_name)
npc_option_button.set_item_tooltip(npc_option_button.item_count - 1, node.get_path()) npc_option_button.set_item_tooltip(npc_option_button.item_count - 1, node.get_path())
func mark_agent_active_for_debug() -> void:
if _debug_bt_player == null:
return
var instance: BTInstance = _debug_bt_player.get_bt_instance()
var blackboard: Blackboard = instance.get_blackboard()
if mark_npc_for_debug.pressed:
blackboard.set_var("debug_npc_path", _debug_agent.get_path())
func unmark_agent_active_for_debug() -> void:
if _debug_agent == null:
return
var instance: BTInstance = _debug_bt_player.get_bt_instance()
var blackboard: Blackboard = instance.get_blackboard()
if mark_npc_for_debug.pressed:
blackboard.set_var("debug_npc_path", NodePath())
func _on_npc_name_edit_text_submitted(new_text: String) -> void:
unmark_agent_active_for_debug()
_debug_agent = get_tree().root.find_child(new_text, true, false) as NonPlayerCharacter
if not is_instance_valid(_debug_agent):
push_error("Cannot show npc behavior: could not find node with name '%s'." % new_text)
return
_debug_bt_player = _debug_agent.find_child("BTPlayer") as BTPlayer
if _debug_bt_player == null:
behavior_debug_view.clear()
push_error("Cannot show npc behavior: no BTPlayer found.")
return
if mark_npc_for_debug.pressed:
mark_agent_active_for_debug()
func _on_mark_npc_for_debug_toggled(toggled_on: bool) -> void: func _on_mark_npc_for_debug_toggled(toggled_on: bool) -> void:
DebugSystem.debug_npc = null
if toggled_on: if toggled_on:
mark_agent_active_for_debug() DebugSystem.debug_npc = _debug_agent
func _on_npc_option_button_item_selected(index: int) -> void: func _on_npc_option_button_item_selected(index: int) -> void:
_debug_agent = get_tree().root.get_node(npc_option_button.get_item_tooltip(index)) as NonPlayerCharacter _debug_agent = get_tree().root.get_node(npc_option_button.get_item_tooltip(index)) as NonPlayerCharacter
if _debug_agent: if _debug_agent:
_debug_bt_player = _debug_agent.find_child("BTPlayer") as BTPlayer _debug_bt_player = _debug_agent.find_child("BTPlayer") as BTPlayer
if _debug_agent is NonPlayerCharacter and mark_npc_for_debug.button_pressed:
DebugSystem.debug_npc = _debug_agent
if _debug_bt_player == null: if _debug_bt_player == null:
behavior_debug_view.clear() behavior_debug_view.clear()
push_error("Cannot show npc behavior: no BTPlayer found.") push_error("Cannot show npc behavior: no BTPlayer found.")
return return