Original post:
I’ve been trying for now literal weeks to fix this and it’s driving me genuinely actually mad so finally just posting it everywhere until I find the solution. I still haven’t figured out how to even share this information correctly to get solutions which is why I have taken so long to ask for help.
Course: Complete Godot 3D: Code Your Own 3D Games In Godot 4!
Section Robo Rampage
The error:
E 0:00:17:111 enemy.gd:61 @ look_at_target(): Node origin and target are in the same position, look_at() failed.
<C++ Error> Condition "p_pos.is_equal_approx(p_target)" is true.
<C++ Source> scene/3d/node_3d.cpp:1067 @ look_at_from_position()
<Stack Trace> enemy.gd:61 @ look_at_target()
enemy.gd:50 @ _physics_process()
The exact function it’s calling this error:
func look_at_target(direction: Vector3) -> void:
var adjusted_direction = direction
adjusted_direction.y = 0
look_at(global_position + adjusted_direction, Vector3.UP, true)
What is happening in game?: Player walks close enough to the enemy causing him to be provoked and try to chase the player - he cannot reach the player due to level design set up. When the player stops moving the error begins to pop every frame.
Picture below, the enemy attempting to reach the player causing the debugger to go off is the one I have circled in red.
Here are the process and physics process functions, since this error comes every second I assume something in these might be able to get modified to fix the issue as well.
func _process(_delta: float) -> void:
if provoked:
navigation_agent_3d.target_position = Player.global_position
func _physics_process(delta: float) -> void:
var next_position = navigation_agent_3d.get_next_path_position()
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
var direction = global_position.direction_to(next_position)
var distance = global_position.distance_to(Player.global_position)
if distance <= aggro_range:
provoked = true
if provoked:
if distance <= attack_range:
playback.travel("attack")
if direction:
look_at_target(direction)
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
I’ve done so many adjustments to the code trying to fix this with positions, directions, global positions, trying is_equal_approx, != to things, etcetcetc - I am sad this reads like it should be easy to fix and I cannot find anyone else dealing with this exactly in a way that they found or shared a solution that works.
Someone else in the GameDev discord brought up the fact they have this issue though today, and it reminded me I still haven’t fixed it; after spending almost two hours this morning on it - someone pretty please tell me they have resolved his already since the course is from gamedev?
