Roblox · Обби · урок 3

Исчезающие ступени, платформа и конвейер

Три новых препятствия: ступени, которые растворяются под ногами, платформа, которая возит игрока, и лента-конвейер, против которой надо бежать.

Структура

Синим — что добавляем на этом уроке.

Workspace
├─ Stairs (Folder)
│  └─ Step (Part) — жёлтая ступенька
│     └─ DisappearScript (Script)
├─ MovingPlatform (Part) — передняя грань (Front) — куда ехать
│  └─ MoveScript (Script)
└─ Conveyor (Part) — Anchored вкл.
   └─ ConveyorScript (Script)

Шаги

  1. Ступенька «Step» со скриптом «DisappearScript». Готовую ступень копируй Ctrl+D — скрипт копируется вместе с ней.
  2. Цикл for i = 1, 20 делает ступень прозрачнее по шагам: i / 20 — от 0.05 до 1. Флаг busy не даёт запустить исчезание второй раз, пока идёт первое.
  3. Платформа «MovingPlatform» 6 × 1 × 6, Anchored вкл. (скрипт сам её отпустит). Поверни так, чтобы передняя грань (View → Orientation Indicator или Front в Surface) смотрела туда, куда ехать.
  4. Почему не меняем Position в цикле, как в методичке: закреплённая деталь «телепортируется» кусочками, и игрок на ней не едет, а проваливается. AlignPosition двигает платформу силой — игрок стоит на ней и едет.
  5. Конвейер «Conveyor»: длинная деталь, Anchored вкл. Скорость AssemblyLinearVelocity у закреплённой детали её не двигает, но всё, что на ней стоит, едет. Направление — передняя грань.
  6. Поверни конвейер передней гранью назад по полосе — игроку придётся бежать против ленты. Перед ним удобно поставить SpeedBrick.

Скрипты

DisappearScript

Где: Workspace → Stairs → Step · Script
Зачем: Ступень растворяется и через 2 секунды возвращается.

-- ступенька
local part = script.Parent
-- ступень уже исчезает — повторные касания не считаем
local busy = false

-- касание
part.Touched:Connect(function(hit)
    -- уже исчезает — выходим
    if busy then return end
    -- исчезает только от игрока
    if not hit.Parent:FindFirstChildOfClass("Humanoid") then return end
    -- занято
    busy = true
    -- 20 шагов
    for i = 1, 20 do
        -- с каждым шагом прозрачнее
        part.Transparency = i / 20
        -- всего за 1 секунду
        task.wait(0.05)
    -- конец цикла
    end
    -- сквозь ступень можно упасть
    part.CanCollide = false
    -- 2 секунды её нет
    task.wait(2)
    -- снова видна
    part.Transparency = 0
    -- снова твёрдая
    part.CanCollide = true
    -- готова к следующему игроку
    busy = false
-- конец функции
end)

MoveScript

Где: Workspace → MovingPlatform · Script
Зачем: Возит платформу туда-обратно.

-- платформа
local platform = script.Parent
-- сколько studs проезжает
local DISTANCE = 14
-- за сколько секунд
local TIME = 3

-- откуда
local start = platform.Position
-- куда: вперёд по передней грани (Front)
local finish = start + platform.CFrame.LookVector * DISTANCE

-- точка, за которую тянем
local attachment = Instance.new("Attachment")
-- в центре платформы
attachment.Parent = platform
-- сила, которая тянет деталь в точку
local align = Instance.new("AlignPosition")
-- тянем к координате, а не к другой детали
align.Mode = Enum.PositionAlignmentMode.OneAttachment
-- кого тянем
align.Attachment0 = attachment
-- сила без предела — игрок её не остановит
align.MaxForce = math.huge
-- скорость: путь за TIME секунд
align.MaxVelocity = DISTANCE / TIME
-- быстро реагирует
align.Responsiveness = 50
-- пока стоим на месте
align.Position = start
-- в платформу
align.Parent = platform
-- держит платформу ровно
local turn = Instance.new("AlignOrientation")
-- к заданному повороту
turn.Mode = Enum.OrientationAlignmentMode.OneAttachment
-- кого держим
turn.Attachment0 = attachment
-- жёстко, без раскачки
turn.RigidityEnabled = true
-- поворот как сейчас
turn.CFrame = platform.CFrame.Rotation
-- в платформу
turn.Parent = platform

-- теперь её двигает физика — игрок едет вместе с ней
platform.Anchored = false
-- физику платформы считает сервер — без рывков
platform:SetNetworkOwner(nil)

-- бесконечно туда-обратно
while true do
    -- едем вперёд
    align.Position = finish
    -- доехали и стоим секунду
    task.wait(TIME + 1)
    -- едем обратно
    align.Position = start
    -- доехали и стоим
    task.wait(TIME + 1)
-- конец цикла
end

ConveyorScript

Где: Workspace → Conveyor · Script
Зачем: Лента тащит игрока.

-- лента (Anchored вкл.)
local part = script.Parent
-- скорость ленты; игрок ходит со скоростью 16
local SPEED = 12

-- закреплённая деталь не едет, но везёт всех, кто на ней
part.AssemblyLinearVelocity = part.CFrame.LookVector * SPEED

Проверка

Запусти Play (или Run) и убедись:

Roblox · Obby · lesson 3

Disappearing steps, a moving platform and a conveyor

Three new obstacles: steps that dissolve under your feet, a platform that carries the player, and a conveyor belt you have to run against.

Structure

Blue — what we add in this lesson.

Workspace
├─ Stairs (Folder)
│  └─ Step (Part) — a yellow step
│     └─ DisappearScript (Script)
├─ MovingPlatform (Part) — the front face (Front) — the direction to travel
│  └─ MoveScript (Script)
└─ Conveyor (Part) — Anchored on
   └─ ConveyorScript (Script)

Steps

  1. A step "Step" with a script "DisappearScript". Copy a finished step with Ctrl+D — the script is copied along with it.
  2. The loop for i = 1, 20 makes the step more transparent step by step: i / 20 goes from 0.05 to 1. The busy flag prevents starting the fade again while it's running.
  3. A platform "MovingPlatform" 6 × 1 × 6, Anchored on (the script releases it itself). Rotate it so the front face (View → Orientation Indicator or Front in Surface) points where it should travel.
  4. Why we don't change Position in a loop like the workbook does: an anchored part "teleports" in jumps, and a player on it doesn't ride but falls through. AlignPosition moves the platform with force — the player stands on it and rides.
  5. A conveyor "Conveyor": a long part, Anchored on. AssemblyLinearVelocity doesn't move an anchored part, but everything standing on it moves. The direction is the front face.
  6. Turn the conveyor's front face back along the course — the player will have to run against the belt. A SpeedBrick in front of it helps.

Scripts

DisappearScript

Where: Workspace → Stairs → Step · Script
Why: The step dissolves and comes back after 2 seconds.

-- the step
local part = script.Parent
-- the step is already vanishing — ignore repeated touches
local busy = false

-- touch
part.Touched:Connect(function(hit)
    -- already vanishing — exit
    if busy then return end
    -- only a player makes it vanish
    if not hit.Parent:FindFirstChildOfClass("Humanoid") then return end
    -- busy
    busy = true
    -- 20 steps
    for i = 1, 20 do
        -- more transparent with each step
        part.Transparency = i / 20
        -- 1 second in total
        task.wait(0.05)
    -- end of loop
    end
    -- you can fall through the step
    part.CanCollide = false
    -- it's gone for 2 seconds
    task.wait(2)
    -- visible again
    part.Transparency = 0
    -- solid again
    part.CanCollide = true
    -- ready for the next player
    busy = false
-- end of function
end)

MoveScript

Where: Workspace → MovingPlatform · Script
Why: Moves the platform back and forth.

-- the platform
local platform = script.Parent
-- how many studs it travels
local DISTANCE = 14
-- in how many seconds
local TIME = 3

-- from
local start = platform.Position
-- to: forward along the front face (Front)
local finish = start + platform.CFrame.LookVector * DISTANCE

-- the point we pull by
local attachment = Instance.new("Attachment")
-- at the platform's center
attachment.Parent = platform
-- a force that pulls the part to a point
local align = Instance.new("AlignPosition")
-- pull toward a coordinate, not another part
align.Mode = Enum.PositionAlignmentMode.OneAttachment
-- what we pull
align.Attachment0 = attachment
-- unlimited force — a player can't stop it
align.MaxForce = math.huge
-- speed: the distance in TIME seconds
align.MaxVelocity = DISTANCE / TIME
-- responds quickly
align.Responsiveness = 50
-- stay in place for now
align.Position = start
-- into the platform
align.Parent = platform
-- keeps the platform level
local turn = Instance.new("AlignOrientation")
-- toward the set rotation
turn.Mode = Enum.OrientationAlignmentMode.OneAttachment
-- what we hold
turn.Attachment0 = attachment
-- rigid, no wobbling
turn.RigidityEnabled = true
-- the current rotation
turn.CFrame = platform.CFrame.Rotation
-- into the platform
turn.Parent = platform

-- now physics moves it — the player rides along
platform.Anchored = false
-- the server runs the platform's physics — no jerks
platform:SetNetworkOwner(nil)

-- back and forth forever
while true do
    -- go forward
    align.Position = finish
    -- arrived, wait a second
    task.wait(TIME + 1)
    -- go back
    align.Position = start
    -- arrived, wait
    task.wait(TIME + 1)
-- end of loop
end

ConveyorScript

Where: Workspace → Conveyor · Script
Why: The belt drags the player.

-- the belt (Anchored on)
local part = script.Parent
-- belt speed; the player walks at 16
local SPEED = 12

-- an anchored part doesn't move but carries everyone on it
part.AssemblyLinearVelocity = part.CFrame.LookVector * SPEED

Testing

Press Play (or Run) and make sure: