Implement NPC investigation state logic#508
Implement NPC investigation state logic#508luiscarloscontreirassilvestre-art wants to merge 11 commits into
Conversation
This script defines the NPC investigation state, including timers for observing and moving, handling NPC interactions, and managing investigation status.
| # Send signal or command to nearby NPC to investigate | ||
| if npc.has_method("set_investigate_target"): | ||
| npc.set_investigate_target(investigate_location) | ||
| elif npc.has_meta("state_machine"): |
There was a problem hiding this comment.
cogito_npc has a direct reference to it's state machine.
Whats your reasoning for using get_meta / set_meta for this?
| var all_npcs = get_tree().get_nodes_in_group("npc") | ||
|
|
||
| for npc in all_npcs: | ||
| if npc == Host: |
There was a problem hiding this comment.
Not sure if this makes sense. Host is basically the parent node of the state machine, but the way this is written, it implies that it only looks for this statemachines host npc.
|
|
||
| func _call_nearby_npcs(): | ||
| # Find all NPCs in the scene | ||
| var all_npcs = get_tree().get_nodes_in_group("npc") |
There was a problem hiding this comment.
This PR doesn't add or set an "npc" group so this line won't do what it's intended to do.
| enum InvestigateStatus{ OBSERVING, MOVING_TO_LOCATION, INVESTIGATING, COMPLETE = 3 } | ||
| var current_investigate_status : InvestigateStatus = InvestigateStatus.OBSERVING | ||
|
|
||
| @export var investigate_animation : String = "alert" |
There was a problem hiding this comment.
If you're setting a default string, could you set it to an animation that exists?
I know there's no matching animation included but maybe we can repurpose a different one, like the talk or dance one, just so this can be tested.
There was a problem hiding this comment.
Items are dropped to trigger the investigated state.
inventory_interface.gd to notify nearby NPCs after a drop — searching for NPCs in the "npc" group and calling their npc_state_machine.goto("investigate").
dropped_item.find_interaction_nodes()
for node in dropped_item.interaction_nodes:
if node.has_method("get_item_type"):
node.slot_data = slot_data
# Notify nearby NPCs to investigate this drop
var investigate_radius := 8.0
var drop_pos := dropped_item.global_position
var all_npcs := get_tree().get_nodes_in_group("npc")
for npc in all_npcs:
if npc == null:
continue
if not npc.has_method("global_position"):
# assume it's a Node3D-like with property
pass
var dist := npc.global_position.distance_to(drop_pos)
if dist <= investigate_radius:
# Provide investigate target and switch state if possible
if npc.has_method("set_investigate_target"):
npc.set_investigate_target(drop_pos)
else:
# set meta for state to read
npc.set_meta("investigate_location", drop_pos)
if npc.has("npc_state_machine") and npc.npc_state_machine and npc.npc_state_machine.has("investigate"):
npc.npc_state_machine.goto("investigate")
elif npc.npc_state_machine and npc.npc_state_machine.has("investigate"):
npc.npc_state_machine.goto("investigate")
return true
This class provides a method to notify nearby NPCs to investigate a specified location within a given radius. It sets the investigate location meta key and transitions NPCs into the investigate state if applicable.
|
|
"Investigate" Status Implemented |
|
I know the code has some errors, but from my point of view it works. It works for me. But I also know it needs improvement. Now the community has better options. There are other alternatives. This system below hasn't been created yet, it's just an idea. For example, an item drop within a 3D area initiates an investigation. Another option is to have a global location of the active NPC looter position. To create another system, add LootComponent to a box, spawn items. Place NPC on patrol. This makes the NPC looters smarter! |
luiscarloscontreirassilvestre-art
left a comment
There was a problem hiding this comment.
Refactor NPC investigate state logic
luiscarloscontreirassilvestre-art
left a comment
There was a problem hiding this comment.
logi
|
The code was very confusing. Please clean up the code to make it simpler. There are no longer distance limits or animations required for it to work. There needs to be an NPC scene group, but it can be changed to another name. The PR is working without bugs. |




This script defines the NPC investigation state, including timers for observing and moving, handling NPC interactions, and managing investigation status.