|Attention||Topic was automatically imported from the old Question2Answer platform.|
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
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
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?
move_dir=origin, and therefore
transform.looking_at(origin) could generate errors.
by the way, you defined
and you defined
which means that
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