diff --git a/ai/tasks/look_at_location.gd b/ai/tasks/look_at_location.gd index 37e7c7f..892f08b 100644 --- a/ai/tasks/look_at_location.gd +++ b/ai/tasks/look_at_location.gd @@ -21,6 +21,8 @@ func _tick(delta: float) -> Status: 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): 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) - #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) clamp_current_look_angle() diff --git a/ai/tasks/navigate_to_location.gd b/ai/tasks/navigate_to_location.gd index 8cb703b..9928f28 100644 --- a/ai/tasks/navigate_to_location.gd +++ b/ai/tasks/navigate_to_location.gd @@ -20,6 +20,8 @@ func _tick(_delta: float) -> Status: 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() if agent_npc.is_navigation_target_reached() or distance_to_target < distance: agent_npc.navigation_active = false diff --git a/ai/trees/wander.tres b/ai/trees/wander.tres index a4b372c..676b06d 100644 --- a/ai/trees/wander.tres +++ b/ai/trees/wander.tres @@ -16,7 +16,7 @@ var/debug_npc_path/hint_string = "" script = ExtResource("1_5wpmm") radius = 3.0 output_var = &"target_location" -navigatable_target = false +navigatable_target = true stay_in_radius = true [sub_resource type="BTAction" id="BTAction_lschq"] diff --git a/objects/non_player_character.gd b/objects/non_player_character.gd index 61102e5..c8c6167 100644 --- a/objects/non_player_character.gd +++ b/objects/non_player_character.gd @@ -61,6 +61,13 @@ func _ready() -> void: func _physics_process(_delta: float) -> void: if navigation_active: 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()): breakpoint diff --git a/project.godot b/project.godot index 886ec65..1ac14d5 100644 --- a/project.godot +++ b/project.godot @@ -23,6 +23,12 @@ config/icon="res://icon.svg" DialogueManager="*res://addons/dialogue_manager/dialogue_manager.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] diff --git a/systems/DebugSystem.gd b/systems/DebugSystem.gd new file mode 100644 index 0000000..6701109 --- /dev/null +++ b/systems/DebugSystem.gd @@ -0,0 +1,5 @@ +extends Node + +var player:Player = null +var debug_node:Node = null +var debug_npc:NonPlayerCharacter = null diff --git a/ui/debug/behaviour.gd b/ui/debug/behaviour.gd index fcb07af..da7ab35 100644 --- a/ui/debug/behaviour.gd +++ b/ui/debug/behaviour.gd @@ -38,55 +38,21 @@ func update_npc_option_button() -> void: npc_option_button.add_item(node_name) 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: + DebugSystem.debug_npc = null if toggled_on: - mark_agent_active_for_debug() + DebugSystem.debug_npc = _debug_agent 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 if _debug_agent: _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: behavior_debug_view.clear() push_error("Cannot show npc behavior: no BTPlayer found.") return -