Godot Version
Godot_v4.3-stable_win64
Question
How can I make sure the target_reached signal fires so I can execute a function once the player and enemy collide?
For reference I used this tutorial to set up the enemy character’s movement via a navigation agent. Around ‘7:42’ (link should go to this timestamp) he sets up the “target_reached()” signal :
In my project for some reason the signal never fires even though the enemy is colliding with my player. I’ll show some screenshots and add the scripts of the enemy and the main level we’re testing in for context below!
The main level, enemy colliding with player but no signal from the target_reached function is printed as I have it set to do from my enemy script :
func _on_navigation_agent_3d_target_reached():
print("Cooper reached!")
I do see this error though when running and I’m wondering if this is causing the problem, possibly? :
E 0:00:01:0102 doppelganger.gd:11 @ _physics_process(): NavigationServer navigation map query failed because it was made before first map synchronization.
NavigationServer 'map_changed' signal can be used to receive update notifications.
NavigationServer 'map_get_iteration_id()' can be used to check if a map has finished its newest iteration.
<C++ Source> modules/navigation/nav_map.cpp:141 @ get_path()
<Stack Trace> doppelganger.gd:11 @ _physics_process()
I was reading it could be caused by frame issues and running navigation set up in the ready function but mine runs in the physics_process_delta function within my main level scene :
extends Node3D
@onready var Cooper = $Cooper
func _physics_process(delta):
get_tree().call_group("Enemies", "_update_target_location", Cooper.global_transform.origin)
This is the main level with a navigation mesh attached to the floor, along with the node tree.
Here is the enemy called the “Doppelganger” scene, node tree and script.
extends CharacterBody3D
@onready var NavAgent = $NavigationAgent3D
@onready var DS_AP = $DoppelgangerSkin/AnimationPlayer
@onready var DS : Node3D = %DoppelgangerSkin
@export var move_speed = 8
func _physics_process(delta):
var current_location = global_transform.origin
var next_location = NavAgent.get_next_path_position()
var new_velocity = (next_location - current_location).normalized() * move_speed
velocity = velocity.move_toward(new_velocity, .25)
move_and_slide()
DS.look_at(next_location)
DS.rotate_object_local(Vector3.UP, PI)
DS_AP.play("Walk002")
func _update_target_location(target_location):
NavAgent.set_target_position(target_location)
func _on_navigation_agent_3d_target_reached():
print("Cooper reached!")
Thanks for reading! The only issue I can think of is using box shapes instead of capsule shapes like the tutorial but for some reason they have just tended to work better for me.