Menu
CoddyTech

開閉するドア

Coddyの「Robloxゲーム:暗闇からの脱出」コースのレッスン 3/25。

ロビーのドアにはProximityPromptがあります。近づくと、プレイヤーには「E 開く」(スマートフォンではタップ)が表示され、操作するとプレイヤーとともにプロンプトのTriggeredが発火します。

ドアは中央ではなく、ヒンジを軸に回転します。ドアモデルには、端に見えないHingeパーツがあります。ヒンジから測ったパネルの位置はhinge.CFrame:ToObjectSpace(panel.CFrame)です。ヒンジを4分の1回転させて、その位置関係を適用すると、ドアが開いた状態になります。

local goal = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0) * hinge.CFrame:ToObjectSpace(panel.CFrame)
TweenService:Create(panel, TweenInfo.new(0.6), { CFrame = goal }):Play()

トゥイーンを使うと、ドアは跳ねるのではなく、滑らかに開きます。ドアが開くと、Open属性が設定され、プロンプトが無効になります。

challenge icon

チャレンジ

簡単

ロビーのドアを開くように回転させます。

  1. TweenServiceを取得します。openDoor(door)を記述し、Open属性をtrueに設定して、door.Panel.Promptを無効にします。
  2. 次に、door.Panelを0.6秒かけて本体のgoalまでTweenさせます。正の方向に4分の1回転させる値はmath.rad(90)です。
  3. setupDoor(door)を記述します。ドアが開いていない場合にdoor.Panel.Prompt.Triggeredでドアを開きます。workspace.Rooms.Lobby.Doorに対して呼び出します。

「プレイ」を押して、ドアのところでEキーを押します。ドアが自分から離れる方向に開きます。その後、「確認」を押します。

自分で試してみよう

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Lighting = game:GetService("Lighting")
local Settings = require(game.ReplicatedStorage.Settings)

-- 夜になる:太陽はなく、あたりにはわずかな光と霧がある
Lighting.ClockTime = Settings.ClockTime
Lighting.Ambient = Settings.Ambient
Lighting.OutdoorAmbient = Settings.Ambient
Lighting.FogColor = Color3.new(0, 0, 0)
Lighting.FogEnd = Settings.FogEnd
print("Lights out")

-- レッスン 3:揺れ動くドアをここに追加する

-- すべてのプレイヤー:リスポーンするたびに懐中電灯を持つ
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		local flashlight = ServerStorage.Flashlight:Clone()
		flashlight.Parent = player.Backpack
		local beam = flashlight.Handle.Beam
		flashlight.Activated:Connect(function()
			beam.Enabled = not beam.Enabled
		end)
	end)
end)

Robloxゲーム:暗闇からの脱出のすべてのレッスン

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