Up vector and direction between node origin and target are aligned, look_at() failed

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

So sick of this stupid error. This is the code that causes it. How can I prevent this? It happens whenever shooting a surface that has a normal that equals straight up or straight down. The queue_free() part also produces an error (“Resumed after yield, but class instance is gone”) if I I back out of the level to the main menu in my game and wait for it to time out, but that is a separate issue.

func bullet_hole(location, normal):
	var bulletHole = resources.decalScenes["Bullet_Hole"].instance()
	add_child(bulletHole)
	bulletHole.global_transform.origin = location + normal * 0.001
	bulletHole.look_at(location - normal, Vector3(0,1,0))
	var random = RandomNumberGenerator.new()
	random.randomize()
	bulletHole.rotation_degrees.z = random.randf_range(0.0,180.0)
	yield(get_tree().create_timer(15.0,false),"timeout")
	if is_instance_valid(bulletHole):
		bulletHole.queue_free()

I have the exact same use case and problem. I’m not sure why the look_at function throws errors like this, it’s very frustrating

Grid Sherman | 2020-02-18 00:24

1 Like
:bust_in_silhouette: Reply From: Sir_Skurpsalot

I fixed it, I changed the code to this:

func Spawn_BulletHole(location, normal,collider):
	var bulletHole = MODELS["Bullet Hole"].instance()
	collider.add_child(bulletHole)
	bulletHole.global_transform.origin = location + normal * 0.001
	if normal == Vector3.DOWN:
		bulletHole.rotation_degrees.x = 90
	elif normal != Vector3.UP:
		bulletHole.look_at(location - normal, Vector3(0,1,0))
	var random = RandomNumberGenerator.new()
	random.randomize()
	bulletHole.rotation_degrees.z = random.randf_range(0.0,180.0)
	yield(get_tree().create_timer(15.0,false),"timeout")
	if is_instance_valid(bulletHole):
		bulletHole.queue_free()	

In summary my bullethole model is oriented facing up in it’s scene, and I have a check that tells it to not bother with the look_at function If the collider normal is straight down or straight up. If the normal is straight down (like the ceiling or underside of a table or something) I flip it over “manually” using rotation_degrees.x. I have not gotten any more errors since I changed the code to this.

I added a solution

Sir_Skurpsalot | 2020-02-18 00:49

I have this same problem, but I was just wondering how you call the function? I don’t have much experience with functions in Godot, and when I go to type Spawn_BulletHole() I don’t know what to type in the parameters.
Also, thank you because I think you solved my problem (once I figure out how to call the function XD)

Redical | 2022-11-15 07:34