Menu
CoddyTech

上昇する溶岩

Coddyの「Robloxゲーム:エンドレスタワー」コースのレッスン 11/21。

下で待っていても安全ではありません。溶岩のシートがタワーの下から始まり、Settings.LavaDelay秒後に一定の速さで上昇し、頂上の2 studs下まで達するので、全員が登り続ける必要があります。

トゥイーンは開始前に待機できます。TweenInfo.newの6番目の引数は秒単位の遅延です。一定の速さで上昇させるには、トゥイーンの時間を距離÷速度で求めます。

-- 4秒後に、毎秒3スタッドの速さで60スタッド移動
local info = TweenInfo.new(60 / 3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 4)

溶岩は固体ではなく(CanCollideはfalse)、誰もその上に立てません。また、Touchedにはキルブリックと同じ関数であるkillOnTouchを使います。高さ-2から始まり、top - 2まで上昇します。これはちょうどtop studsの高さです。

challenge icon

チャレンジ

中級

溶岩は塔の下で上昇します。

  1. buildTowerがtopを返すようにし、スクリプトの最後をstartLava(buildTower())にします。
  2. startLava(top)を記述します。トップレベルのlavaを、アンカーされたLavaという名前のPartに設定し、CanCollideをfalseにして、(0, -2, 0)に配置し、TouchedをkillOnTouchに接続します。
  3. top / Settings.LavaSpeed秒かけてLinearで(0, top - 2, 0)までTweenし、Settings.LavaDelayだけ遅延させます。

「プレイ」を押します。10秒後、溶岩があなたの下から上昇し始めます。その後、「確認」を押します。

自分で試してみよう

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
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タグが付いたものに触れると、ライフが1つ失われる
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

-- レーザーはSlideで指定されたオフセットまで滑り、元の位置に戻る動きを繰り返す
local function makeSlide(part)
	local info = TweenInfo.new(Settings.SlideTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true)
	local goal = { Position = part.Position + part:GetAttribute("Slide") }
	TweenService:Create(part, info, goal):Play()
end

-- バウンスパッドは、乗った人を空中へ跳ね上げる
local function bounce(hit)
	local root = hit.Parent:FindFirstChild("HumanoidRootPart")
	if root then
		root.AssemblyLinearVelocity = Vector3.new(0, Settings.BouncePower, 0)
	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
		if part:HasTag("Conveyor") then
			part.AssemblyLinearVelocity = part.CFrame.LookVector * Settings.BeltSpeed
		end
		if part:HasTag("Slider") then
			makeSlide(part)
		end
		if part:HasTag("Bounce") then
			part.Touched:Connect(bounce)
		end
	end
end

-- ステージをランダムに1つ選ぶ
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

-- レッスン11:上昇する溶岩はここに追加する

buildTower()
quiz icon腕試し

このレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。

Robloxゲーム:エンドレスタワーのすべてのレッスン

自分で練習してみよう: Robloxプレイグラウンド