Help with 'look_at' issue with CharacterBody3D NavigationAgent3D requested

Godot Version

v4.7.rc1.official [a4f5e8cdd]

Question

I have a CharacterBody3D ‘Knig_1’ in this code…) following a Navigation Region, with four ‘way-points’, in a loop. This works well, except that I cannot get the Knig_1 to face in the direction of travel. The code I have used in other Projects, which works well, throws an error in this Project…

knig_1.gd:49 @ _physics_process(): Node origin and target are in the same position, look_at() failed.

I don’t understand why this fails, when in my otherwise identical Project it works fine. How may I get this Knig_1 to look forward along his Path, please..? Thanks in advance for an explanation and/or solution; ask if more info is needed. Here’s the total code for this Knig_1, and a screenshot of his Node Tree…

```

class_name Knig_1

extends CharacterBody3D

#@export var lv_move_spee: float = 5.0 # *** Test
@export var lv_move_spee: float = 1.0
@onready var lv_targ_posi := Vector3.ZERO
@onready var lv_navi_agen: NavigationAgent3D = $NavigationAgent3D_Knig_1
@onready var lv_anim_play = $AnimationPlayer
@onready var lv_curr_posi = $“.”.global_position
#@onready var lv_play = $“../Player”
@onready var lv_knig = $“.”
@onready var lv_jolt = true
var lv_targ_coun = 1
var lv_targ_x
var lv_targ_z

@onready var lv_targ_x_1 = $“../Knig_1/Post_K1_1”.global_position.x
@onready var lv_targ_z_1 = $“../Knig_1/Post_K1_1”.global_position.z
@onready var lv_targ_x_2 = $“../Knig_1/Post_K1_2”.global_position.x
@onready var lv_targ_z_2 = $“../Knig_1/Post_K1_2”.global_position.z
@onready var lv_targ_x_3 = $“../Knig_1/Post_K1_3”.global_position.x
@onready var lv_targ_z_3 = $“../Knig_1/Post_K1_3”.global_position.z
@onready var lv_targ_x_4 = $“../Knig_1/Post_K1_4”.global_position.x
@onready var lv_targ_z_4 = $“../Knig_1/Post_K1_4”.global_position.z

const lc_text_walk = “Walking_C”
const lc_text_idle = “Idle_B”
const lc_text_hit = “Hit_B”
const lc_text_die = “Death_B”

func _ready() → void:
jolt()

func _physics_process(_delta: float) → void:
if NavigationServer3D.map_get_iteration_id(lv_navi_agen.get_navigation_map()) == 0:
return
if lv_navi_agen.is_navigation_finished() and lv_jolt == true:
print(“Knight Finished”)
lv_jolt = false
lv_anim_play.play(lc_text_idle)
return
else:
if lv_jolt == true:
var destination = lv_navi_agen.get_next_path_position()
var local_destination = destination - global_transform.origin
var direction = local_destination.normalized()
velocity = direction * (lv_move_spee)
#look_at(global_position - direction) # *** THrows an error (see below…)

knig_1.gd:49 @ _physics_process(): Node origin and target are in the same position, look_at() failed.

		move_and_slide()

func find_path():
if lv_targ_coun == 1:
lv_targ_x = lv_targ_x_1
lv_targ_z = lv_targ_z_1
if lv_targ_coun == 2:
lv_targ_x = lv_targ_x_2
lv_targ_z = lv_targ_z_2
if lv_targ_coun == 3:
lv_targ_x = lv_targ_x_3
lv_targ_z = lv_targ_z_3
if lv_targ_coun == 4:
lv_targ_x = lv_targ_x_4
lv_targ_z = lv_targ_z_4
lv_targ_coun += 1
if lv_targ_coun >4:
lv_targ_coun = 1
lv_curr_posi = lv_knig.global_position
lv_targ_posi.x = lv_targ_x
lv_targ_posi.y = 0.0
lv_targ_posi.z = lv_targ_z
lv_navi_agen.set_target_position(lv_targ_posi)
lv_anim_play.play(lc_text_walk)
#print("Next Target : ",lv_targ_coun)

func jolt():
lv_jolt = true
lv_targ_x = lv_targ_x_1
lv_targ_z = lv_targ_z_1
lv_anim_play.play(lc_text_walk)
find_path()

func _on_navigation_agent_3d_knig_navigation_finished():
find_path()

```

Call look_at() only if direction is not zero.

Thanks; I’ll try that straight away.
In the meantime, what is the secret code for getting the correct formatting here..? I’m in France, with a French keyboard, the the ‘</>’ gives poor result. I’ve tried three ‘tildes’, and three ‘accent graves’, and other occult combinations, but I’ve not yet been lucky this time. Any advice, from someone in France with an AZERTY keyboard, maybe..? Thanks in advance
Now to test direction for zero. I don’t suppose that’s as simple as ‘if direction == zero’ by any chance..?

You can try pressing ctrl+E and paste code between the tags.

Nope; same block of badly-formatted text. Thanks, though.

More to the point, vis : my question… It did the trick. Testing ‘if direction != Vector3.ZERO’ worked. Why I haven’t had this issue in other Projects, doing ostensibly the same thing, I don’t know. Just lucky, maybe..? At least I now now how to treat the issue if/when it crops up again, so thanks for that.
It’s now 03h30; time to wrap up for this evening, methinks. I’ll ‘flag’ your reply as The Solution. Cheers; have a great day.