Godot Version
4.5.1
Question
So I’m trying to make a tube scene that connects with other tubes using 3 preset sprites (straight, L left, & L right). It half works, but not as I intended
This is the “HyperTube” script:
extends GridObject2D
@onready var target_pos: Node2D = $target
@onready var right: Node2D = $right
@onready var left: Node2D = $left
@onready var positions: AnimationPlayer = $positions
var target_obj :GridObject2D = null
var temp_left :GridObject2D = null
var temp_right :GridObject2D = null
func update_sprite(object :GridObject2D, from_targ :bool = false) → void:
print(“updated”)
if from_targ or ((round(global_rotation_degrees) == round(object.global_rotation_degrees))):
positions.play(“straight”)
var obj_pos :Vector2 = round(object.global_position)
if obj_pos == round(right.global_position):
positions.play(“L_right”)
if obj_pos == round(left.global_position):
positions.play(“L_left”)
func _on_ready() → void:
update_sprite(self)
global_position = round(global_position)
print([target_pos.global_position, right.global_position, left.global_position])
GridData.add_object(self)
target_obj = GridData.get_object(target_pos.global_position)
if target_obj != null:
print("requesting update")
target_obj.update_sprite(self, true)
temp_left = GridData.get_object(round(left.global_position))
temp_right = GridData.get_object(round(right.global_position))
if temp_left != null:
print("requesting update")
temp_left.update_sprite(self)
if temp_right != null:
print("requesting update")
temp_right.update_sprite(self)
func _exit_tree() → void:
if target_obj != null:
target_obj.update_sprite(self, true)
if temp_left != null:
temp_left.update_sprite(self)
if temp_right != null:
temp_right.update_sprite(self)```

