Beam

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

一個 光束 對象會連接兩個 Attachments 通過繪製在他們之間的紋理。

要顯示,光束必須是 Workspace 的子孫,其 Attachment0Attachment1 屬性設置為 Attachments 也從 Workspace 下降。

光束的外觀可以使用下面列出的屬性範圍進行自訂。也參見光束指南的視覺示例。

光束曲率

光束配置使用由四個控制點形成的立方體Bézier曲線。這意味著它們不受限於直線,光束的彎曲可以通過修改 CurveSize0CurveSize1 和光束的 Attachments 來修改。

Beam curvature diagram

範例程式碼

This code sample demonstrates how a Beam effect can be created from scratch by creating a Beam, setting all of its properties and configuring it's Attachments.

Creating a Beam From Scratch

-- create attachments
local att0 = Instance.new("Attachment")
local att1 = Instance.new("Attachment")
-- parent to terrain (can be part instead)
att0.Parent = workspace.Terrain
att1.Parent = workspace.Terrain
-- position attachments
att0.Position = Vector3.new(0, 10, 0)
att1.Position = Vector3.new(0, 10, 10)
-- create beam
local beam = Instance.new("Beam")
beam.Attachment0 = att0
beam.Attachment1 = att1
-- appearance properties
beam.Color = ColorSequence.new({ -- a color sequence shifting from white to blue
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 255)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 255, 255)),
})
beam.LightEmission = 1 -- use additive blending
beam.LightInfluence = 0 -- beam not influenced by light
beam.Texture = "rbxasset://textures/particles/sparkles_main.dds" -- a built in sparkle texture
beam.TextureMode = Enum.TextureMode.Wrap -- wrap so length can be set by TextureLength
beam.TextureLength = 1 -- repeating texture is 1 stud long
beam.TextureSpeed = 1 -- slow texture speed
beam.Transparency = NumberSequence.new({ -- beam fades out at the end
NumberSequenceKeypoint.new(0, 0),
NumberSequenceKeypoint.new(0.8, 0),
NumberSequenceKeypoint.new(1, 1),
})
beam.ZOffset = 0 -- render at the position of the beam without offset
-- shape properties
beam.CurveSize0 = 2 -- create a curved beam
beam.CurveSize1 = -2 -- create a curved beam
beam.FaceCamera = true -- beam is visible from every angle
beam.Segments = 10 -- default curve resolution
beam.Width0 = 0.2 -- starts small
beam.Width1 = 2 -- ends big
-- parent beam
beam.Enabled = true
beam.Parent = att0

概要

屬性

屬性

Attachment0

平行讀取

光束的起源 Attachment 。此附件是光束的立方體 Bézier 曲線上的第一個控制點;其方向與 CurveSize0 屬性一起,決定了第二個控制點的位置。請參閱光束以獲得更多詳情。

對於 Attachment 光束結束的地方,請參閱 Attachment1

Attachment1

平行讀取

光束將在 Attachment 結束。這個附件是光束的立方體 Bézier 曲線上的第四個和最後控制點;它的方向,與 CurveSize1 屬性一起,決定了第三個控制點的位置。請參閱光束以獲得更多詳情。

對於從光束起源的 Attachment ,請參閱 Attachment0

Brightness

平行讀取

LightInfluence 小於 1 時,縮放射出的光束所發出的亮度。此屬性的值為預設值為 1,可設為 0 到 10000 範圍內的任何數字。增加 LightInfluence 值會減少此屬性值的效果。

平行讀取

決定光束在其 Segments 的顏色。如果 Texture 被設設定,這個顏色將被應用到光束的紋理上。如果沒有設設定 TextureBeam 將以此屬性的顏色顯示為一條牢固的線。

此屬性是 ColorSequence ,允許顏色配置以在光束長度上變化。考慮以下 ColorSequence ,當應用於光束時,將產生圖像的結果。


local colorSequence = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)), -- 紅
ColorSequenceKeypoint.new(0.5, Color3.fromRGB(0, 188, 203)), -- 青綠
ColorSequenceKeypoint.new(1, Color3.fromRGB(196, 0, 255)), -- 紫色
}
)

注意光束的色彩也取決於 Segments 有多少 Beam 。光束的每一個區段只能顯示兩種顏色之間的過渡。因此,一個 Beam 需要至少有 n-1 個區域才能正確顯示顏色,其中 nColorSequenceKeypointsColorSequence 中的數量。

CurveSize0

平行讀取

Attachment0 一起,決定光束的 Bézier 曲線中第二個控制點的位置。請參閱 光束 獲得更多細節。

這個點的位置可以由以下方程式決定:


local controlPoint2 = Beam.Attachment0.WorldPosition + (Beam.Attachment0.CFrame.RightVector * Beam.CurveSize0)

CurveSize1

平行讀取

Attachment1 一起,決定光束的 Bézier 曲線中第三個控制點的位置。請參閱 光束 獲得更多細節。

這個點的位置可以由以下方程式決定:


local controlPoint3 = Beam.Attachment1.WorldPosition - (Beam.Attachment1.CFrame.RightVector * Beam.CurveSize1)

Enabled

平行讀取

決定光束是否可見。

當此屬性設為 false 時,光束的 Segments 將不會顯示。

FaceCamera

平行讀取

A Beam 是在 3D 空間中存在的 2D 投影,意味著它可能不能從每個角度看到。當 面相機 屬性設為 true 時,保證光束總是面向 CurrentCamera,無論其方向如何。

LightEmission

平行讀取

決定光束的顏色與背後顏色的融合程度。應該設置在 0 到 1 之間。0的值使用普通混合模式,1的值使用添加混合模式。

此屬性不應與 LightInfluence 混淆,它決定光束如何受到環境光的影響。

此屬性不會 使光束照亮環境

LightInfluence

平行讀取

決定光束是否受環境燈光的影響程度,介於 0 和 1 之間。當 0 時,光束將不受環境燈光的影響。當 1 時,燈光的影響將完全像 BasePart 一樣。

也可以參考 LightEmission 指定光束顏色與背後顏色的融合程度。

LocalTransparencyModifier

隱藏
未複製
平行讀取

Segments

平行讀取

而不是完美的彎曲線,光束是由直段組成的。段數越多,曲線的解析度越高。 屬性設置光束由多少個直線段組成,預設值為 10。

請注意,ColorTransparency 屬性需要一定數量的段落才能正確顯示。這是因為每個區段只能顯示兩種顏色或透明度之間的轉換。因此,需要至少 Beam 顯示正確的段數 n-1 ,其中 n 是與光束的 ColorTransparency 相關的键點數量。

Texture

ContentId
平行讀取

要顯示在光束上的紋理內容ID。如果此屬性未設設定,光束將以固體線顯示;這也會發生在紋理設為無效內容ID或紋理相關的圖像尚未載入時。

紋理的外觀可以進一步修改其他光束特性,包括 ColorTransparency

紋理的縮放由 TextureModeTextureLengthWidth0Width1 屬性決定。

TextureLength

平行讀取

設置光束的紋理長度,取決於 TextureMode

TextureMode

平行讀取

這個屬性,與 TextureLength 一起,決定光束的 Texture 重複方式。

當設為 Enum.TextureMode.WrapEnum.TextureMode.Static 時,紋理重複將等於光束的總長(以學分為單位)除以其 TextureLength

TextureMode diagram with Wrap mode

當設為 Enum.TextureMode.Stretch 時,紋理會在光束的整體長度上重複 TextureLength 次。

TextureMode diagram with Stretch mode

TextureSpeed

平行讀取

決定圖像 Texture 在光束上移動的速度。當此屬性為正值時,光束的紋理將從 Attachment0 移動到 Attachment1 。將此屬性設為負數可以反轉此方向。

Transparency

平行讀取

決定光束在其各個部分的透明度。此屬性是 NumberSequence ,允許透明度配置在光束長度上變化。

考慮以下 NumberSequence ,當應用於光束時,將產生圖像結果。


local numberSequence = NumberSequence.new({
NumberSequenceKeypoint.new(0, 0), -- 不透明
NumberSequenceKeypoint.new(0.5, 1), -- 透明
NumberSequenceKeypoint.new(1, 0), -- 不透明
}
)

請注意,光束的透明度也取決於 Segments 的數量。光束的每一個區段只能顯示兩個透明度之間的轉換。因此,光束需要至少有 n-1 個段落才能正確顯示,其中 nNumberSequenceKeypointsNumberSequence 中的數量。

Width0

平行讀取

在其原點的光束寬度(Attachment0),以厘米為單位。光束的寬度將在其末端變更為Width1厘米(Attachment1)。

Width1

平行讀取

在其末端的光束寬度( Attachment1 ),以厘米為單位。光束的寬度將從其起源的 Width0 厘米線性變化( Attachment0 )。

ZOffset

平行讀取

光束顯示與 CurrentCamera 相對位置的距離,以厘米為單位。當 0 時,光束將在 Attachment0Attachment1 之間的標準位置顯示。 ZOffset 可以是正或負。

這個特性在使用多個 Beams 之間的相同 Attachments 時避免「Z‑戰鬥」特別有用。

範例程式碼

This code sample uses the Beam.ZOffset property to layer multiple beams between the same attachments.

Layering Beams

-- Create beams
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
-- Layer beams
beam1.ZOffset = 0
beam2.ZOffset = 0.01
beam3.ZOffset = 0.02
-- Create attachments
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
-- Connect beams
beam1.Attachment0 = attachment0
beam1.Attachment1 = attachment1
beam2.Attachment0 = attachment0
beam2.Attachment1 = attachment1
beam3.Attachment0 = attachment0
beam3.Attachment1 = attachment1
-- Parent beams
beam1.Parent = workspace
beam2.Parent = workspace
beam3.Parent = workspace

方法

SetTextureOffset

()

光束的紋理週期抵消代表其紋理動畫的進度。這個方法設置了光束的紋理週期目前偏移值;因此,可以使用 0 作為 offset 參數來重設週期。

注意事項

  • 給出的 offset 參數預期為 0 與 1 之間的值,但可以使用更大的值。
  • 紋理循環在 0 和 1 結束,表示紋理在偏移為 0 或 1 時的相同位置。
  • 如果 Texture 屬性未設設定,此方法無作用。
  • 增加抵消將在反向方向上作用於 TextureSpeed 屬性,意味著它將在 TextureSpeed 大於 0 時將紋理向相反的方向移動到紋理動畫的方向。

參數

offset: number

紋理週期的預期偏移量。

預設值:0

返回

()

活動