コードサンプル
ゼロからビームを作成する
-- アタッチメントを作成
local att0 = Instance.new("Attachment")
local att1 = Instance.new("Attachment")
-- 地形に親を設定(代わりにパートでも可)
att0.Parent = workspace.Terrain
att1.Parent = workspace.Terrain
-- アタッチメントの位置を設定
att0.Position = Vector3.new(0, 10, 0)
att1.Position = Vector3.new(0, 10, 10)
-- ビームを作成
local beam = Instance.new("Beam")
beam.Attachment0 = att0
beam.Attachment1 = att1
-- 外観プロパティ
beam.Color = ColorSequence.new({ -- 白から青への色のシーケンス
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 255)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 255, 255)),
})
beam.LightEmission = 1 -- 加算ブレンディングを使用
beam.LightInfluence = 0 -- ビームは光の影響を受けない
beam.Texture = "rbxasset://textures/particles/sparkles_main.dds" -- 組み込みのスパークルテクスチャ
beam.TextureMode = Enum.TextureMode.Wrap -- テクスチャの長さで設定するためラップ
beam.TextureLength = 1 -- 繰り返しテクスチャは1スタッドの長さ
beam.TextureSpeed = 1 -- テクスチャ速度は遅い
beam.Transparency = NumberSequence.new({ -- ビームが最後にフェードアウト
NumberSequenceKeypoint.new(0, 0),
NumberSequenceKeypoint.new(0.8, 0),
NumberSequenceKeypoint.new(1, 1),
})
beam.ZOffset = 0 -- オフセットなしでビームの位置にレンダリング
-- 形状プロパティ
beam.CurveSize0 = 2 -- 曲がったビームを作成
beam.CurveSize1 = -2 -- 曲がったビームを作成
beam.FaceCamera = true -- ビームはあらゆる角度から見える
beam.Segments = 10 -- デフォルトの曲線解像度
beam.Width0 = 0.2 -- 小さく始まる
beam.Width1 = 2 -- 大きく終わる
-- ビームを親にする
beam.Enabled = true
beam.Parent = att0APIリファレンス
プロパティ
Texture
Beam.Texture:ContentId
ZOffset
コードサンプル
レイヤリングビーム
-- ビームを作成
local beam1 = Instance.new("Beam")
beam1.Color = ColorSequence.new(Color3.new(1, 0, 0))
beam1.FaceCamera = true
beam1.Width0 = 3
beam1.Width1 = 3
local beam2 = Instance.new("Beam")
beam2.Color = ColorSequence.new(Color3.new(0, 1, 0))
beam2.FaceCamera = true
beam2.Width0 = 2
beam2.Width1 = 2
local beam3 = Instance.new("Beam")
beam3.Color = ColorSequence.new(Color3.new(0, 0, 1))
beam3.FaceCamera = true
beam3.Width0 = 1
beam3.Width1 = 1
-- ビームを重ねる
beam1.ZOffset = 0
beam2.ZOffset = 0.01
beam3.ZOffset = 0.02
-- アタッチメントを作成
local attachment0 = Instance.new("Attachment")
attachment0.Position = Vector3.new(0, -10, 0)
attachment0.Parent = workspace.Terrain
local attachment1 = Instance.new("Attachment")
attachment1.Position = Vector3.new(0, 10, 0)
attachment1.Parent = workspace.Terrain
-- ビームを接続
beam1.Attachment0 = attachment0
beam1.Attachment1 = attachment1
beam2.Attachment0 = attachment0
beam2.Attachment1 = attachment1
beam3.Attachment0 = attachment0
beam3.Attachment1 = attachment1
-- ビームを親にする
beam1.Parent = workspace
beam2.Parent = workspace
beam3.Parent = workspace方法