This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi guys, I'm getting lots of this error message with lookingat and moveand_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?

Godot version 3.2
in Engine by (516 points)

At first glance it looks fine - at least better than I would write it :)
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.

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...

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...

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]?

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.

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 )*

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.

1 Answer

0 votes

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

by (1,514 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.