I am curently making a 2D Endless runner and i am trying to let my Pre-built obstacles spawn based on my Backround . the obstacles also contain the Ground for the player to walk on so they have to be spawned Without any gaps
So the obstacles are just made with a Tileset and they and the Colision shaped (wich are death Zones and Jumppads) should be Spawned in the main Scene the Backround was just for reference for Scale.
And what have i tried : i am prety new to it so i Tried using yt tutorial but none realy Fit what i want to do and i also Tried using Ai but that did not work
I’m not sure what your question really is but I try to give you some ideas:
you can build you or level with tile maps (platforms, walls, etc)
the endless aspect of your platformer is more or less generating level content
My first steps would be:
build an initial level with some elements you want to use (platforms with gaps, walls, whatever…)
implement your movement, jumping, etc.
After that I would start generating level content because you should have some constraints already (you know what you have to generate).
Now you will have to find mechanism to generate platforms. That’s very subjective and depends heavily on your requirements.
Your question sounded more conceptual so a gave a more general answer. Hope that helps a bit
I mean i wanted it to be more like the lvl Generation in SubwaySurfers where you have ~10 Diferent prebuild Sections and they Randomly Spawn behind each other . and i want to prebuild 10 of the ones in the pic . (When i then am further i thought about adding biomes where then the obstacles look diferent in each one ) But for now just trying to get it ti work with no biomes
You basically build segments as tiles maps and spawn them as needed.
Say you have 10 segments aka 10 different tile maps. You start with 1 or 2 and on certain triggers you spawn the next one at the position you want it.
So you don’t have to spawn multiple objects or manipulate single tiles. You probably just need to define some kind of interface between each segment so they fit together
ok i lett chat gbt cook but now the segment sometimes spawn at the same time and sometimes just dont at all
extends Node
@export var obstacle_scenes: Array = []
@export var distance_between_obstacles: float = 544.0
@export var spawn_interval: float = 2.0
var last_obstacle_position: float = 0.0
var time_since_last_spawn: float = 0.0
func _ready():
var scene1 = ResourceLoader.load("res://Scene/Hindernis/hindernis_1.tscn") as PackedScene
var scene2 = ResourceLoader.load("res://Scene/Hindernis/hindernis_2.tscn") as PackedScene
if scene1:
obstacle_scenes.append(scene1)
if scene2:
obstacle_scenes.append(scene2)
last_obstacle_position = -distance_between_obstacles
spawn_obstacle()
func _process(delta):
time_since_last_spawn += delta
if time_since_last_spawn >= spawn_interval:
spawn_obstacle()
time_since_last_spawn = 0.0
func spawn_obstacle():
if obstacle_scenes.size() == 0:
print("Error: obstacle_scenes array is empty.")
return
var obstacle_scene = obstacle_scenes[randi() % obstacle_scenes.size()]
if obstacle_scene:
var obstacle_instance = obstacle_scene.instantiate()
if obstacle_instance is Node2D:
var new_position = last_obstacle_position + distance_between_obstacles
obstacle_instance.position = Vector2(new_position, 0) # Position im 2D-Raum
add_child(obstacle_instance)
last_obstacle_position = new_position
else:
print("Error: Instantiated scene is not of type Node2D.")
else:
print("Error: obstacle_scene is null.")
Tile maps can make your life way easier.
May start with a tutorial on how to make a simple platformer so you understand the basics.
Generating your level in the fly is just additionally making your gameplay more pleasant.
Therefore you need core gameplay and some definitions. Like what is a segment?
This may be a good start for most of the fundamentals you need: