Good day Defolders so I’m making an endless runner game with platforms based on the old runner tutorial but I have encountered an issue in the tutorial the game has one type of long platform and one kind of short platform but I created 5 types of short platforms and 5 types of long platforms and I was thinking of a way to make them spawn randomly using the behaviour of the tutorial script I tried creating another local variable to spawn the other ones but it ended up filling the screen with platforms, what changes do I have to make to this script to make that possible again I’m trying to make the game spawn more than two types of platforms but in the way the script does it that it doesn’t fill the screen here is the original script
self.gridw = self.gridw + self.speed * dt
if self.gridw >= grid then
self.gridw = 0
-- Maybe spawn a platform at random height
if math.random() > 0.2 then
local h = platform_heights[math.random(#platform_heights)]
local f = "#grassplatform2"
if math.random() > 0.5 then
f = "#grassplatformlong2"
end
local p = factory.create(f, vmath.vector3(1600, h, 0), nil, {}, 0.6)
msg.post(p, "set_speed", { speed = self.speed })
end
end
end
and this is the script of what i tried doing
-- controller.script
go.property("speed", 500)
local grid = 460
local platform_heights = { 200, 350, 400, 500, 510, 600} -- <1>
local platforms = "#rockplatform2","#grassplatform2"
local long_platforms = "#rockplatformlong", "#grassplatformlong2"
function init(self)
msg.post("ground/control#ground", "set_speed", { speed = self.speed })
msg.post("Dave#Character", "set_speed", { speed = self.speed })
self.gridw = 0
end
function update(self, dt) -- <2>
self.gridw = self.gridw + self.speed * dt
if self.gridw >= grid then
self.gridw = 0
-- Maybe spawn a platform at random height
if math.random() > 0.2 then
local h = platform_heights[math.random(#platform_heights)]
local f = platforms
if math.random() > 0.5 then
f = long_platforms
end
local p = factory.create(f, vmath.vector3(1600, h, 0), nil, {}, 0.6)
msg.post(t, "set_speed", { speed = self.speed })
end
end
end
Please help