컨베이어 벨트
Coddy의 Roblox 게임: 끝없는 타워 코스 레슨. 18개 중 7번째.
컨베이어 스테이지에는 Conveyor라는 태그가 붙은 어두운 벨트가 있으며, 당신을 왔던 방향으로 밀어냅니다. 고정된 파트는 움직이지 않지만, 여기에 AssemblyLinearVelocity를 지정하면 그 위에 서 있는 것은 무엇이든 실제 벨트처럼 함께 이동합니다.
어느 방향일까요? 모든 파트에는 앞면이 있으며, part.CFrame.LookVector는 그 파트에서 뻗어 나오는 길이 1스터드의 Vector3입니다. 벨트의 앞면은 통로를 따라 뒤쪽을 향하도록 돌려져 있습니다.
part.AssemblyLinearVelocity = part.CFrame.LookVector * Settings.BeltSpeed파트 자체의 방향을 사용하면 제작자가 벨트를 어느 방향으로든 향하게 돌려도 스크립트를 변경할 필요 없이 계속 작동합니다.
챌린지
중급setupStage에서 Conveyor 태그가 지정된 모든 파트의 AssemblyLinearVelocity를 해당 파트의 CFrame.LookVector에 Settings.BeltSpeed를 곱한 값으로 설정하세요.
Play를 누르고 벨트에 맞서 걸어 보세요. 그런 다음 Check를 누르세요.
직접 해보기
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local Settings = require(game.ReplicatedStorage.Settings)
local stages = ServerStorage.Stages
local tower = nil
print("Each tower has " .. Settings.StageCount .. " stages")
-- 모든 플레이어의 리더보드에 Wins가 추가됩니다
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Parent = leaderstats
end)
-- Kill 태그가 붙은 것에 닿으면 생명을 잃습니다
local function killOnTouch(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
-- 사라지는 발판은 누군가 밟은 직후 희미해졌다가 다시 나타납니다
local function makeVanish(part)
part.Touched:Connect(function(hit)
if part:GetAttribute("Gone") or not hit.Parent:FindFirstChild("Humanoid") then
return
end
part:SetAttribute("Gone", true)
task.wait(Settings.VanishDelay)
part.Transparency = 0.8
part.CanCollide = false
task.wait(Settings.VanishTime)
part.Transparency = 0
part.CanCollide = true
part:SetAttribute("Gone", nil)
end)
end
-- 회전 장애물은 매 프레임 조금씩 회전합니다
RunService.Heartbeat:Connect(function(dt)
for _, spinner in CollectionService:GetTagged("Spinner") do
if spinner:IsDescendantOf(workspace) then
spinner:PivotTo(spinner:GetPivot() * CFrame.Angles(0, math.rad(Settings.SpinSpeed) * dt, 0))
end
end
end)
-- 태그에 따라 스테이지의 모든 장애물을 활성화합니다
local function setupStage(stage)
for _, part in stage:GetDescendants() do
if part:HasTag("Kill") then
part.Touched:Connect(killOnTouch)
end
if part:HasTag("Vanish") then
makeVanish(part)
end
end
end
-- 스테이지를 무작위로 하나 선택합니다
local function pickStage()
local all = stages:GetChildren()
return all[math.random(1, #all)]
end
-- 모델의 복사본을 타워 꼭대기에 놓고, 복사본과 새로운 꼭대기 높이를 반환합니다
local function stack(template, bottom)
local copy = template:Clone()
local box, size = copy:GetBoundingBox()
local lift = bottom - (box.Position.Y - size.Y / 2)
copy:PivotTo(copy:GetPivot() + Vector3.new(0, lift, 0))
copy.Parent = tower
return copy, bottom + size.Y
end
-- 아래에서 위로 새로운 무작위 타워를 만듭니다
local function buildTower()
tower = Instance.new("Model")
tower.Name = "Tower"
tower.Parent = workspace
local top = 0
for i = 1, Settings.StageCount do
local stage, newTop = stack(pickStage(), top)
top = newTop
setupStage(stage)
end
stack(ServerStorage.Finish, top)
end
buildTower()
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.