0 votes

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 onTimertimeout():
var obstacle = OBSTACLE.instance()
add
child(obstacle)

func onScoreTimertimeout():
Global.current
score +=1

func process(delta):
$Label.text = "" +str(Global.current
score)

Godot version GLES2
in Engine by (17 points)

1 Answer

0 votes

Every time you create a platform you need to generate a random number (see https://docs.godotengine.org/en/stable/tutorials/math/random_number_generation.html)

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

by (82 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.