Hi, just created first script. Why dont work always instantiate blocks with same gap.
extends CanvasGroup
var left_two = preload("res://scenes/left_two.tscn")
var left_three = preload("res://scenes/left_three.tscn")
var lastPos = Vector2(-32, 0)
var scaleLast = Vector2.ZERO
var scaleNew = Vector2.ZERO
var gap = 400
var block_size = 10
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
for i in block_size:
var random_block = randi_range(0, 1)
if random_block == 0:
var newBlock = left_two.instantiate()
scaleNew = newBlock.get_scale()
newBlock.set_global_position(Vector2(lastPos.x + (scaleLast.x / 2) + gap + (scaleNew.x / 2), position.y))
lastPos = newBlock.position
scaleLast = newBlock.get_global_scale()
add_child(newBlock)
print("left two")
if random_block == 1:
var newBlock = left_three.instantiate()
scaleNew = newBlock.get_scale()
newBlock.set_global_position(Vector2(lastPos.x + (scaleLast.x / 2) + gap + (scaleNew.x / 2), position.y))
lastPos = newBlock.position
scaleLast = newBlock.get_global_scale()
add_child(newBlock)
print("left three")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass