Godot Version
4.3
Question
Hello, im trying first time Godot, for a little game.
i have
the blue one say no “cennection” the red one say yes we have a connection.
i dont know whats the problem and i hope smn can help me here
this is the code for the coeection
func check_connections():
neighbors.clear()
var direction_offsets = [
Vector2(32, 0), Vector2(-32, 0),
Vector2(0, 32), Vector2(0, -32)
]
var self_position = global_position.snapped(Vector2(32, 32))
print("🛠 Überprüfung für Fließband an:", self_position)
var objects = get_tree().get_nodes_in_group("transport")
for obj in objects:
if obj == self: # Sich selbst ignorieren
continue
var obj_position = obj.global_position.snapped(Vector2(32, 32))
for offset in direction_offsets:
var expected_position = self_position + offset
print("Prüfe Nachbarn:", expected_position, "vs", obj_position)
if expected_position == obj_position:
neighbors.append(obj)
print("Nachbar gefunden an:", obj_position)
connected = neighbors.size() > 0
print("Fließband an Position", self_position, "hat", neighbors.size(), "Nachbarn.")
and on the controller i have.
func place_conveyor():
var pos = get_global_mouse_position().snapped(Vector2(32, 32))
# Prüfen, ob bereits ein Fließband an genau dieser Position existiert
for obj in get_tree().get_nodes_in_group("transport"):
if obj.global_position == pos:
print("Platzierung fehlgeschlagen: Bereits ein Fließband an", pos)
return
var conveyor_instance = conveyor_scene.instantiate()
conveyor_instance.position = pos
add_child(conveyor_instance)
print("Fließband erfolgreich platziert an", pos)
# wait 2 frames
await get_tree().process_frame
await get_tree().process_frame
# check all tracks
for obj in get_tree().get_nodes_in_group("transport"):
obj.check_connections()
I hope someone can help me to understand why the blue ones not connecting.
Thanks