Raycast 3d nodes not hitting

Godot Version

godot 4

Question

I have a shotgun that iterates through a series of raycast3d nodes to check for damage whenever you shoot. for some reason none of these raycasts return anything. here’s my code:

func _process(delta):
	if Input.is_action_just_pressed("Shoot") && ammo > 0 && get_parent().name == "playerHands":
		ammo -= 1
		anim.play("Flash") 
		for ray in rayParent.get_children():
			if ray.is_colliding():
				print(ray.get_collider().name)
				if ray.get_collider.has_method("takeDamage"):
					ray.get_collider.takeDamage(throwDmg, ray.get_collider)
			else:
				print("not hitting")

everytime I shoot, regardless of what I’m pointing at, I get “not hitting” printed to console. I’m certain my collision masks are set up correctly to hit what they’re meant to, what’s the issue?

part of the issue, I just realized, was the rays were parented to a node, not a node3d, and because of this I didn’t realize I was missing the parenthesis at the end of my ray.get_collider calls(I think the rays literally just weren’t part of the physics in the scene… maybe I’m wrong but I changed it and started getting errors so IDK). despite fixing this, raycasts seem to be going through my intended target still, which is odd

Have you tried activating “visible collision-shapes” in the debug-menu when testing?

1 Like

I have not. I appreciate your time but I ended up going with physics-based bullets instead.

2 Likes