How to set Different various platforms at different size + Radomly generate

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Starlight_Chronix

I’m new to coding trying to create a 2d endless runner and only have one platform and struggling on how to generate different various platforms I don’t want them to be the same size as the first one I want more than one platform you could jump on and to also have them be in different sizes. One last thing the platforms only come in a straight line I want the platforms to randomly generate all over.

extends Node2D

const OBSTACLE = preload(“res://scenes/Platform_big.tscn”)

func _ready():
Global.current_score = 0

func _on_Timer_timeout():
var obstacle = OBSTACLE.instance()
add_child(obstacle)

func _on_ScoreTimer_timeout():
Global.current_score +=1

func _process(delta):
$Label.text = “” +str(Global.current_score)

:bust_in_silhouette: Reply From: Bimi124

Every time you create a platform you need to generate a random number (see Random number generation — Godot Engine (stable) documentation in English)

Everything you need to do after this is setting the obstacles y position to the random number you just generated.

how would I randomize the positioning specifically cause it’d either not work or I would get an error. Here’s the script for the platform for a better reference

extends StaticBody2D

func _ready():
randomize()

func _process(delta):
position.x -= (370) * delta

Starlight_Chronix | 2022-01-07 02:37