Look_at broken in 4.4

Godot Version

4.4

Question

I have a navigation agent3d and the following code:

func _toPoint(delta):
	var dir = global_position.direction_to(navAgent.get_next_path_position())
	velocity = dir * speed
	look_at(navAgent.get_next_path_position(), Vector3(0,1,0))
	move_and_slide()

In 4.3 the player turned to the position and walked towards it. In 4.4 the player rotates in place, merging with the ground and every frame this error shows up:

W 0:00:02:567   ClickToMove.gd:66 @ _toPoint(): Target and up vectors are colinear. This is not advised as it may cause unwanted rotation around local Z axis.
  <C++ Source>  core/math/basis.cpp:1058 @ looking_at()
  <Stack Trace> ClickToMove.gd:66 @ _toPoint()
                ClickToMove.gd:29 @ _process()

The line 66 is the look_at line in the first code block.

Tried to block rotations, set diferent up directions but i was unable to solve it

The function get_next_path_position() will return the agents parent node if it doesnt have a next position.

The colinear error is indicating that the up vector used with look_at and the returned path position are the same direction.

I dont think look_at is the issue, its probably your navigation path, or an unhandled edge case where the path and up vector of look_at are identical.

1 Like

But on 4.3 worked tho.

I dont think think its the lack of a next position
Ive placed breakpoints and the player and the next target is not the same

The function was changed between 4.3 and 4.4. but 4.3 would not log a fatal error unless a build flag MATH_CHECK was defined. 4.4 now tries to resolve the issue and only reports a warning.

So it seems like its still your navigation input is the issue. If the cross product of the next path with up vector is near zero, it is mathematically an issue. You can also just ignore it as it is a warning.

Or i would move your agent away from the first path position.

1 Like

I’m facing the same issue, but even though I’ve put several agents on the scene and I make them roam around to random positions, that warning appears few times.
Might it be that the NavigationServer, sometimes, returns paths having two consecutive segments that are actually colinear and that causes the warning?

@pennyloafers is right; this isn’t the functions, it’s the data you’re feeding them.

You should probably be checking the distance between global_position and the return value of get_next_path_position() before you do anything else. If they’re nearly or exactly the same position, you’ll get zeroes and infinities in ugly places in the math, which will give you difficult to diagnose visual glitches or even crashes.

I’d suggest something like:

func _toPoint(delta):
    var nextpos = navAgent.get_next_path_position()

    if global_position.distance_to(nextpos) < 0.01: # Within 1cm...
        global_position = nextpos # Just snap.
        return

    var dir = global_position.direction_to(nextpos)
    #...