Save the starting position when the bullet spawns, and if the current position > starting position + preferred distance, queue free.
example (use these scripts on the bullets, which i assume is a rigid body 2d):
extends RigidBody2D
var start = Vector2.ZERO
var direction = Vector2.ZERO
var max = 50 # adjust this in distance
func _ready():
start = position
func _physics_process():
position += direction
var dist = abs(cartesian2polar(position - startpos).x)
if dist > max:
self.queue_free()
or alternitavely, you can set a timer and queue free on timeout.
example:
extends RigidBody2D
var start = Vector2.ZERO
var direction = Vector2.ZERO
var maxtime = 2.0 # adjust this in seconds
func _ready():
var timer = Timer.new()
timer.wait_time = maxtime
timer.autostart = true
add_child(timer)
timer.connect("timeout", self, "on_timeout")
func on_timeout():
self.queue_free()
func _physics_process():
position += direction