Staircase Builder
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 6 of 25.
In the last lesson i moved each pillar along one direction. A staircase needs every step to go up and forward at the same time, so i goes into two of the three numbers.
Say each step is 1 stud thick. For step i to have its top at height i, its center must be half a stud lower: i - 0.5. To move each step 2 studs closer to the goal along Z, subtract i * 2 from where you start:
for i = 1, 3 do
print(i - 0.5, 10 - i * 2)
endThis prints 0.5 8, 1.5 6 and 2.5 4: the Y and Z of three steps climbing toward Z 0. print with several values separates them with a space.
In this game a player walks up a step about 1 stud high; anything taller needs a jump.
Challenge
EasyBuild a staircase up to the yellow block, which is too high to jump.
- The loop already makes 10 steps, all in one spot. Find the
step.Positionline. - Change it to
Vector3.new(0, i - 0.5, 10 - i * 2): stepihas its top at heightiand is 2 studs closer than the last.
Press Play: ten steps climb to the block and you can walk up. Then Check.
Try it yourself
for i = 1, 10 do
local step = Instance.new("Part")
step.Name = "Step"
step.Size = Vector3.new(6, 1, 2)
step.Anchored = true
-- Each step is 1 stud higher and 2 studs closer to the yellow block
step.Position = Vector3.new(0, 0.5, 10)
step.Parent = workspace
end
All lessons in Roblox Game Scripting
2Loops and Functions
Row of PillarsStaircase BuilderTower BuilderCoin FactoryBlinking LightVanishing Bridge5Your First Game
Your First ObbyPractice on your own: Online Lua compiler