ShapeCast3D, Hurtbox/Hitbox

Godot Version

Godot 4.6.2

Question

Hello I have created shapecast for my “arrow” so it can collide with objects etc. to be “destroyed” so it doesnt pierce infinitely. But I have a problem when I stand in melee range with enemy and try to shoot it gets deleted before it can triggered the hitbox/hurtbox collisions. Any ideas how to fix that issues? GDscript bellow is the projectile.

extends HurtBox

@export var speed := 4
@export var max_distance := 80
@export var shooter: Node3D

@onready var ray := $RayCast3D

var direction: Vector3 = Vector3.ZERO
var start_position := Vector3.ZERO

func _ready():
	start_position = global_position
	if shooter:
		$ShapeCast3D.add_exception(shooter)
		
func _physics_process(delta):
	var motion = direction.normalized() * speed * delta
	
	$ShapeCast3D.force_shapecast_update()
	
	if $ShapeCast3D.is_colliding():
		queue_free()
		return
	
	global_position += motion
	
	if global_position.distance_to(start_position) >= max_distance:
		queue_free()