Error: look_at_from_position: Up vector and direction between node origin and target aligned, look_at() failed.

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

Hello!
I finally got bullet holes working in my game, but I get this error (as typed in title), and it’s very weird how I get the error: I have to be jumping and running while shooting at the ground.
It doesn’t affect anything, so I looked up how to disable errors but the error continued.
Also, here’s the bullet hole code (which works so far):

var b = b_decal.instance()
aimcast.get_collider().add_child(b)
b.global_transform.origin = aimcast.get_collision_point()
b.look_at(aimcast.get_collision_point() + aimcast.get_collision_normal(), Vector3.UP)

It’s probably a really simple fix, it’s just I keep getting annoyed at seeing the error every time I test my game.
Thanks for any help. :slight_smile:

:bust_in_silhouette: Reply From: Juxxec

From the look_at documentation:

The target position cannot be the same as the node’s position, the up vector cannot be zero, and the direction from the node’s position to the target vector cannot be parallel to the up vector.

It is probably just that. While looking at the ground, the look at vector becomes parallel to the up vector. In that case there is no need to call the look_at function:

if aimcast.get_collision_normal().dot(Vector3.UP) > 0.001:
    b.look_at(aimcast.get_collision_point() + aimcast.get_collision_normal(), Vector3.UP)

Hello!
Thanks for replying.
I tried what you said, and I thought it worked, but it still says the error.
I may have coded it wrong, so here’s the script (there’s more in the script but it’s not really important):

if aimcast.is_colliding():
		var target = aimcast.get_collider()
		if aimcast.get_collision_normal().dot(Vector3.UP) > 0.001:
			var b = b_decal.instance()
			aimcast.get_collider().add_child(b)
			b.global_transform.origin = aimcast.get_collision_point()
			b.look_at(aimcast.get_collision_point() + aimcast.get_collision_normal(), Vector3.UP)

Is there something wrong with the way I’ve added what you told me?

Redical | 2022-12-02 11:37

no this answer is totally correct you cant look_at to from where you want to look_at
and you’ll probably need to do a check to that effect

Wakatta | 2022-12-03 02:57

Right.
So - sorry I’m still new to Godot - what do you mean? Is there something I need to change to stop the error? Because also now I’ve changed a couple things and the bullet decal doesn’t show on flat walls, but it shows on everything else. I’ll be able to fix that I think, it’s just I think that might be affecting something now too.
It’s not important though, I’ll ask another question if that becomes a problem.

Redical | 2022-12-03 11:23

Juxxec already provided the example check

if aimcast.get_collision_normal().dot(Vector3.UP) > 0.001:

So you’re checking to make sure that the spacial isn’t at the location is trying to look at.

var direction = aimcast.get_collision_point() + aimcast.get_collision_normal()
if b.global_transform.origin != direction:
    b.look_at(direction , Vector3.UP)

The flat surface error is most likely a depth issue with the decal. Do a simple test to verify.

Wakatta | 2022-12-03 13:16

Oh, I just got it to work!
I changed it to:

if aimcast.get_collision_normal().dot(Vector3.UP) > 0.0000000000000000000001:

… Then the code you’ve said before.
But, now I have yet another problem… So sorry about how difficult this has become…
Whenever I shoot at a surface that isn’t the floor while jumping, sometimes the bullet decal rotates incorrectly and is facing the same way it is in the bullet decal scene (Along -Z).
Here’s the code:

if aimcast.is_colliding():
			var target = aimcast.get_collider()
			var b = b_decal.instance()
			target.add_child(b)
			if aimcast.get_collision_normal().dot(Vector3.UP) > 0.0000000000000000000001:
				b.global_transform.origin = aimcast.get_collision_point()
				var direction = aimcast.get_collision_point() + aimcast.get_collision_normal()
				if b.global_transform.origin != direction:
					b.look_at(direction, Vector3.UP)

Thanks for any help. Again… :slight_smile:

Redical | 2022-12-03 22:51