set_look_at: condition "v_x.length() == 0" is true

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi guys, I’m getting lots of this error message with looking_at and move_and_slide on a navigation mesh. I just want my kinematic body to smoothly rotate itself to its movement vector as it’s move_and_slide’ing towards its target. It’s always worked fine until now. This is my code:

var move_vec = (path[path_ind] - global_transform.origin)    
var move_dir = global_transform.origin + move_vec
var rot = global_transform.looking_at(move_dir, Vector3.UP)
set_global_transform(global_transform.interpolate_with(rot, delta*accel))

Like I said, never had a problem with this code before, until now. What is the problem?

At first glance it looks fine - at least better than I would write it :slight_smile:
Could you somehow narrow down which line exactly is throwing error?

Also, make sure, that you don’t have any missing variables. For example path could be empty but I’m just shooting blind here.

Skipperro | 2021-01-13 20:00

the line with the problem is this:

var rot = global_transform.looking_at(move_dir, Vector3.UP)

There are no empty variables… I’m racking my brains here…

Macryc | 2021-01-13 20:04

hacked my way around it by putting a if move_vec.x != 0: condition above the code, as clearly Godot had a problem with the movement vector x coordinate sometimes being equal to 0. I am not sure that is the best way of dealing with this issue though. Neither do I understand why Godot would have a problem with this in the first place. Look_at has a similar problem…

Macryc | 2021-01-13 21:09

i never had this issue with looking/look at.
what error doest it print? can you maybe share this part of the project to test?

by the way, is it me or move_dir=path[path_ind]?

Andrea | 2021-01-15 15:18

What the error prints is in the title of this thread.
The movement direction isn’t just a path point. It’s the difference between the node’s position and the path point.

Macryc | 2021-01-15 15:42

oh sorry, didnt notice it was on the title.
could it be that you are asking the transform to look at itself?
If move_vec=Vector3(0,0,0), then move_dir=origin, and therefore transform.looking_at(origin) could generate errors.

by the way, you defined move_dir=origin+mov_vec
and you defined mov_vec=path-origin
which means that move_dir=origin+path-origin=path

EDIT: nope, i just checked, transform.looking_at(transform.origin) returns a different error ( set_look_at: Condition "p_eye == p_target" is true )

Andrea | 2021-01-15 15:56

What you’re saying makes sense. I got this snippet from a tut and never really paid much attention as it always just worked. I’ll try and add the path point (as opposed to move vec) to the origin to get direction. It will be almost the same thing except the move vec will never be 0.

Macryc | 2021-01-15 16:20

:bust_in_silhouette: Reply From: Andrea

found it, this error appears when the target you want to look at is exactly alligned with the “up” vector. eg:

var target=Vector3(0,10,0)
var tform=Transform.IDENTITY
print(tfrom.looking_at(target, Vector3(0,1,0))

this happens because The transform will first be rotated around the given up vector, and then fully aligned to the target by a further rotation around an axis perpendicular to both the target and up vectors.

but if the up vector is already perfectly alligned with the target, it cannot find the perpendicular axis for the second step.
Not a real error tbh