i get this error sometimes>

E 0:00:20:0532 _process: Up vector and direction between node origin and target are aligned, look_at() failed.
<C++ Fout> Condition "p_up.cross(p_target - p_pos).is_equal_approx(Vector3())" is true.
<C++ Bron> scene/3d/node_3d.cpp:796 @ look_at_from_position()
this is the code

if result:
			var collider = result.collider
			var n = result.normal
			var p = result.position
		
			var impact = impact_normal.instantiate()
			collider.add_child(impact)
			var impactparticles = impact_particles.instantiate()
			get_tree().get_root().add_child(impactparticles)
		
		
			impact.global_transform.origin = p 
			if (p == n):
				impact.look_at(n)
			else:
				impact.look_at(p + n)

how do i fix it?

  • The error is happening when result.normal is (0,1,0), or extremely close to it.
    look_at() defaults to assuming the up direction of the node is (0,1,0). Usually this is fine, when you look in most directions you don't want the node rolling to the side or upside down. But when you want to look directly up, look_at() doesn't know exactly what you want, there's an infinite number of ways to look straight up. So in that situation you need to give it an alternative up vector.
    (The same thing would happen with trying to look straight down)

    So the way to solve it would be to check if result.normal is very close to vertical (up or down) and if so then provide an up vector to look_at().

    Something like (untested):

    if (abs(n.y)>0.99):
    	impact.look_at(p+n, Vector3(0,0,1))
    else:
    	impact.look_at(p+n)

    This is the equivalent of telling a person that when they look directly up, the top of their head should point south.
    The abs() part is to check both looking straight up and down in one go.
    I don't know if 0.99 is too or not enough lenient, I don't know what is_equal_approx's precision is. Should be ok. Better to trigger it more often than needed (might visually be off a fraction of a degree) than not enough (error happens).

Yes, this is standard if the vectors are too close. You can just add a little bit.

impact.global_transform.origin = p 
impact.look_at(p + n + Vector3(0.001, 0.0, 0.0))

I don't think you need that last if statement, just the code above should work.

    The error is happening when result.normal is (0,1,0), or extremely close to it.
    look_at() defaults to assuming the up direction of the node is (0,1,0). Usually this is fine, when you look in most directions you don't want the node rolling to the side or upside down. But when you want to look directly up, look_at() doesn't know exactly what you want, there's an infinite number of ways to look straight up. So in that situation you need to give it an alternative up vector.
    (The same thing would happen with trying to look straight down)

    So the way to solve it would be to check if result.normal is very close to vertical (up or down) and if so then provide an up vector to look_at().

    Something like (untested):

    if (abs(n.y)>0.99):
    	impact.look_at(p+n, Vector3(0,0,1))
    else:
    	impact.look_at(p+n)

    This is the equivalent of telling a person that when they look directly up, the top of their head should point south.
    The abs() part is to check both looking straight up and down in one go.
    I don't know if 0.99 is too or not enough lenient, I don't know what is_equal_approx's precision is. Should be ok. Better to trigger it more often than needed (might visually be off a fraction of a degree) than not enough (error happens).

    cybereality
    This will fix it for the case of the normal being directly up or down. But the error is still there, just rotated slightly to the side. A normal of (-0.001,0.999,0) will trigger the error.

      Kojack But the error is still there, just rotated slightly to the side.

      Yes, I know, but with floating-point inaccuracy, it is unlikely to ever be exactly equal.