Menu
CoddyTech

움직이는 레이저

Coddy의 Roblox 게임: 끝없는 타워 코스 레슨. 21개 중 9번째.

Lasers 스테이지에는 Slider와 Kill이라는 태그가 붙은 빨간 벽이 두 개 있으며, 이 벽들은 통로를 가로질러 갔다가 되돌아옵니다. 각 벽에는 Slide라는 속성이 있으며, 이 속성은 벽이 시작 위치에서 어디로 이동하는지를 나타내는 Vector3입니다.

트윈은 반복할 수 있습니다. TweenInfo.new에는 시간, 이징, 방향, 반복 횟수(-1은 무한 반복을 뜻함), 그리고 역방향으로 재생할지 여부를 전달합니다.

local info = TweenInfo.new(2.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true)
TweenService:Create(part, info, { Position = part.Position + part:GetAttribute("Slide") }):Play()

Linear는 속도를 일정하게 유지하므로 플레이어가 움직임을 가늠할 수 있습니다. 기본 이징(Quad, Out)은 도착할 때 속도를 늦추므로 타이밍을 맞추기 어렵습니다.

challenge icon

챌린지

중급

레이저가 통로를 가로질러 이동했다가 돌아오게 하세요.

  1. 위쪽에서 TweenService를 가져오세요.
  2. makeSlide(part)를 작성하세요. 파트의 Position을 현재 Position에 Slide 속성 값을 더한 위치로 트윈하세요. Linear 방식으로 Settings.SlideTime초 동안 진행하고, 무한 반복(-1)하며 되돌아오게 하세요.
  3. setupStage에서 Slider 태그가 있는 모든 파트에 이 함수를 호출하세요.

‘플레이’를 누르세요. 빨간 벽 두 개가 일정한 속도로 가로질러 이동했다가 돌아옵니다. 그런 다음 ‘확인’을 누르세요.

직접 해보기

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

-- 레슨 9: 슬라이딩 레이저를 여기에 추가합니다

-- 스피너는 매 프레임 조금씩 회전합니다
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
		if part:HasTag("Conveyor") then
			part.AssemblyLinearVelocity = part.CFrame.LookVector * Settings.BeltSpeed
		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()

Roblox 게임: 끝없는 타워의 모든 레슨

직접 연습해 보세요: Roblox 플레이그라운드