上昇する溶岩
Coddyの「Robloxゲーム:エンドレスタワー」コースのレッスン 10/18。
最下部で待っていても安全ではありません。溶岩のシートは塔の下から始まり、少し遅れてから、頂上の2 studs下まで一定の速度で上昇するため、全員が登り続けなければなりません。
トゥイーンは開始前に待機できます。TweenInfo.newの6番目の引数は秒単位の遅延です。一定の速度で上昇させるには、トゥイーンの時間を距離÷速度にします。
local seconds = top / Settings.LavaSpeed
local info = TweenInfo.new(seconds, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, Settings.LavaDelay)溶岩は固体ではなく(CanCollideはfalse)、誰もその上に立つことはできません。また、そのTouchedにはキルブリックと同じ関数であるkillOnTouchを使います。高さ-2から始まり、top - 2まで上昇します。これはちょうどtop studsです。
チャレンジ
中級- 上部付近に
local lava = nilを追加します。buildTowerがtopを返すようにします。 startLava(top)を記述します。アンカーされたLavaという名前の Part を作成します。CanCollide は無効にし、サイズを 30 × 2 × 30、位置をVector3.new(0, -2, 0)に設定します。オレンジ色の Neon(Color3.fromRGB(255, 90, 20))にして、workspace に配置し、Touched をkillOnTouchに接続します。その Position をVector3.new(0, top - 2, 0)まで、top / Settings.LavaSpeed秒かけて、Linear で Tween します。開始までにSettings.LavaDelay秒の遅延を入れます。- 最後に、
local top = buildTower()の後にstartLava(top)を記述します。
このレッスンの溶岩は速く動くので、Check はすぐに終わります。Play を押してから、Check を押します。
自分で試してみよう
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タグが付いたものに触れるとライフを失う
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
buildTower()
このレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。