How do you stop clones into getting stuck inside walls

Godot Version

4.5

Question

How do you stop clones form getting stuck in walls

My cloning Script

func _unhandled_input(event: InputEvent) → void:
if event.is_action_pressed(“mitosis”) and count_duplicates < 7:
count_duplicates += 1
var copy = duplicate()
copy.position.x += randf_range(5, 15)
add_sibling(copy)

This line “teleports” the duplicate to the right, so if there’s a wall to the right, it’ll be teleported into the wall. If that’s not what you want, you need to change this part. How you should change it depends what you want to happen specifically. If you describe in more detail what you want to happen, then we might be able to better help you.

even if i remove that If i create a clone to close to the wall it will get stuck