Hello fellows!
I’m learning Godot 3D. I’m working on a infinite runner mobile game. But I’m struggling with iteration of my obstacles.
I’m following this tutorial but when getting to the iteration part there is gaps between each obstacle
I’ve been testing out some alternatives than the one on the video. But nothing have done the work yet.
My question
Is there any way to get the size of my obstacles? Or should I calculate the proper offset for each iteration? If so… I have no idea how to even get close to that ![]()
My code
Main level script:
extends Node3D
@export var modules: Array[PackedScene]
var amount = 10
var rng = RandomNumberGenerator.new()
var offset = 5
func _ready():
for n in amount:
spawn_module(n * offset)
func spawn_module(n):
rng.randomize()
var num = rng.randi_range(0, modules.size() - 1)
var instance = modules[num].instantiate()
instance.position.z = -n
add_child(instance)
This script run on each obstacle scene:
extends Node3D
var speed = 5
@onready var level := get_parent()
func _process(delta):
position.z += speed * delta
if position.z > 5:
level.spawn_module(position.z + (level.amount * level.offset))
queue_free()
Thanks for your time!
