look_at() gives false error about origin and target being in the same position

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

This is the function I use to usually deal with errors related to look_at.

func new_look_at(node,point):
var _is_zero = (Vector3.UP.cross(point - node.global_transform.origin))
if _is_zero == Vector3():
	return false

if node.global_transform.origin == point:
	return false

print("node pos: ",node.global_transform.origin," target: ",point)
node.look_at(point,Vector3.UP)
return true

I can’t reproduce this error consistently at all, but within 5 minutes or so during gameplay, this error will be made in the console.
enter image description here

With the origin and target being printed below.

But as you can see, Origin and Target isn’t the same at all, yet this error is caused.

for context ‘new_look_at’ is called every time a bullet is created. I have used this function since Godot 3 with no errors until now.

But as you can see, Origin and Target isn’t the same at all, yet this error is caused.

The line right above the ERROR shows they’re pretty close so maybe this is a rounding issue. They’re pretty close, meaning this engine code:

bool AABB::is_equal_approx(const AABB &p_aabb) const {
	return position.is_equal_approx(p_aabb.position) && size.is_equal_approx(p_aabb.size);
}

Is likely true for such small values (looks like only Z differs by a fraction). Unsure if this changed with the engine version, but I’d likely handle it here:

if node.global_transform.origin == point:
    return false

With a similar check (is_equal_approx) rather than an exact comparison (which is only likely to be true with Vector2i; unsure if the engine does is_equal_approx). Test it to find out!

spaceyjase | 2023-04-14 15:22

You’re right, I feel so stupid now. For some reason I thought the print below the error was the result of the error. I must’ve been tilted or sleep deprived lol

I’ll try it out.

sotlol | 2023-04-14 20:41