軌跡 對象用於創建兩個附件之間的軌跡效果。隨著附件移動通過空間,會在其定義的平面上畫出一個材質。這常常用於創建像追蹤軌跡在發射物、腳踏軌跡、足跡軌跡和類似效果的效果。
有關更多資訊,請參閱 軌跡。
範例程式碼
This example demos the functionality of Trails by creating a BasePart to be the parent of the trail. Two Attachments are then parented to the part. The positions of these two attachments (more importantly the distance between them) determines where the trail is drawn as the part moves.
For these attachments to create a trail as described, a new Trail is parented to the part and its Attachment0 and Attachment1 are parented to attachment0 and attachment1 respectively. Finally, TweenService is used to move the part back and forth, showing how the trail is drawn as the part (and its attachments) move.
local TweenService = game:GetService("TweenService")
-- Create a parent part
local part = Instance.new("Part")
part.Material = Enum.Material.SmoothPlastic
part.Size = Vector3.new(4, 1, 2)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.Parent = workspace
-- Create attachments on part
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
-- Create a new trail
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = part
-- Tween part to display trail
local dir = 15
while true do
dir *= -1
local goal = {Position = part.Position + Vector3.new(0, 0, dir)}
local tweenInfo = TweenInfo.new(3)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(4)
end
概要
屬性
以下 Attachment1 與 Class.Trail.附件1|附件1 一起,決定軌跡的分段將在哪裡開始畫畫。
以下 Attachment0 與 Class.Trail.附件0|附件0 一起,決定軌跡的分段將在哪裡開始畫畫。
當 LightInfluence 小於 1 時,縮放發射的光從軌跡。
軌跡的顏色 throughout its lifetime。
決定是否要畫筆軌跡。
決定軌跡將隨時面向相攝影機,無論其方向。
決定每個軌跡的每個區段的長度,以秒計。
決定彩色軌跡的顏色與背後的顏色的比例。
決定徑跡是否受到環境燈光的影響程度。
設定軌跡的最大長度。
設定軌跡的最小長度。
展示軌跡上的材料 ID。
設定軌跡的材質長度,取決於 TextureMode 。
決定<Class.Trail.Texture|Texture>的尺寸、重複和移動方式,以及跟蹤的附件。
設定軌跡的片段透明度 Lifetime 。
擴展徑的寬度。
屬性
Brightness
當 LightInfluence 小於 1 時,減少發射的光從軌跡中發射的光。這個屬性預設為1,可以設為任何範圍內的數字。提升 LightInfluence 的值會減少此屬性的效果。
Color
在整個生命時間內決定軌跡的顏色。如果 Texture 已設定,這個顏色會漆畫紋理。
這個屬性是 ColorSequence ,允許顏色在軌跡長度上變化。如果顏色在某些軌跡區段已被畫畫後,顏色會變更。所有舊區段都會更新,以符合新顏色。
範例程式碼
This example creates a Trail with a gradient color, meaning that the color at one end of the trail is different than the color at the opposite end, and both colors blend together as they get closer to the middle of the trail.
local TweenService = game:GetService("TweenService")
-- Create a parent part
local part = Instance.new("Part")
part.Material = Enum.Material.SmoothPlastic
part.Size = Vector3.new(4, 1, 2)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.Parent = workspace
-- Create attachments on part
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
-- Create a new trail with color gradient
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
local color1 = Color3.fromRGB(255, 0, 0)
local color2 = Color3.fromRGB(0, 0, 255)
trail.Color = ColorSequence.new(color1, color2)
trail.Parent = part
-- Tween part to display trail
local dir = 15
while true do
dir *= -1
local goal = {Position = part.Position + Vector3.new(0, 0, dir)}
local tweenInfo = TweenInfo.new(3)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(4)
end
Enabled
此屬性決定是否要畫筆軌跡。
如果設為 false 而且有一個正在畫畫的軌跡,就不會畫畫新的軌跡,但現有的軌跡將被自然地清理,當它們達到其 Lifetime 的終點。要強制清理現有軌跡時,請在同一時間呼叫 Class.
FaceCamera
Class.Trail 是存在於 3D 空間中的 2D 投影,意味著它可能無法從每個角度查看。 FaceCamera 屬性,當設為 true ,確保軌跡總是面向 1> Class.Workspace.CurrentCamera|CurrentCamera1> ,無論其方向。
變更此屬性會立即影響所有現有和未來的軌跡區段。
Lifetime
永久 屬性決定每個軌跡中的每一個區段在何時出現之前,在秒鐘後,會持續的時間。預設為 2 秒,但可以在 0.01 到 20 之間任何地方設置。
這個效果的 Color 和 Transparency 屬性也用來決定每個區段是否會被绘制。 這兩個屬性都是順序,因此它們在交叉點 Class.Trail.Color 和 2> Class.Trail.Transparency2> 之間定義值。然後在交叉點
如果軌跡的生命時間改變,現有段落將立即變為即使他們總是擁有新的生命時間,這意味著如果他們已存在更長時間,就會立即被移除。
LightEmission
決定彩色軌跡與背後顏色的比例。它應該在 0 到 1 範圍內設置。一個值為 0 使用基本混合模式,一個值為 1 使用添加式混合模式。
此屬性不應與 LightInfluence 相混淆,這是決定軌跡受到環境光影響的方法。
變更此屬性會立即影響所有現有和未來的軌跡區段。
此屬性會導致 不 發生軌跡點亮環境。
LightInfluence
決定程度在 0 和 1 之間的環境照明對軌跡的影響程度。當 0 時,軌跡將不受環境照明的影響。當 1 時,它將完全受到照明的影響,作為 BasePart 的。
變更此屬性會立即影響所有現有和未來的軌跡區段。
也參閱 LightEmission ,以指定紅色軌跡的顏色與背後的顏色的比例。
LocalTransparencyModifier
MaxLength
此屬性確定軌跡的最大長度,以格子計。其值預設為 0,這表示軌跡將不會有最長度,而且軌跡區段將在其 Lifetime 過期。
此屬性可以與 MinLength 屬性一起使用,以確定軌跡必須在畫畫之前的最小長度。
MinLength
此屬性確定軌跡的最小長度,以格子計。如果沒有至少移動此值的尾件,否則將不會創建新的區段,且現有區段的 end點 將移動到新的附件的位置。
注意,變更此屬性只會影響 新 段落,而不會影響 老 段落;如果 老 段落 已經 被 畫 出 ,它 們 會 保 持 現 有 長 度。
此屬性可以與 MaxLength 屬性一起使用,以確定在其最古老的部分被清除之前的最大軌跡長度。
Texture
展示軌跡上的文字資料。如果此屬性未設定,文字資料將以固定飛機顯示;這也會在設置文字資料為無效內容 ID 或屬性與圖像關聯的圖像尚未載入時發生。
材質的外觀可以進一步修改其他軌跡屬性,包括 Color 和 Transparency 。
縮放文本的大小是由 Attachment0 和 Attachment1 以及 TextureMode 、1> Class.Trail.TextureLength|粒度長度1> 和 4>
範例程式碼
This example adds a paw prints texture to a trail object. In order for the paw prints to remain "stamped" in place after rendering, TextureMode is set to Enum.TextureMode.Static.
local TweenService = game:GetService("TweenService")
-- Create a parent part
local part = Instance.new("Part")
part.Material = Enum.Material.SmoothPlastic
part.Size = Vector3.new(2, 1, 2)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.Parent = workspace
-- Create attachments on part
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-1, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(1, 0, 0)
attachment1.Parent = part
-- Create a new trail with color gradient
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Texture = "rbxassetid://16178262222"
trail.TextureMode = Enum.TextureMode.Static
trail.TextureLength = 2
trail.Parent = part
-- Tween part to display trail
local dir = 15
while true do
dir *= -1
local goal = {Position = part.Position + Vector3.new(0, 0, dir)}
local tweenInfo = TweenInfo.new(3)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(4)
end
TextureMode
這個屬性,TextureLength ,決定了軌跡的 Texture 如何縮放、重複和移動。改變此屬性會立即影響所有現有和未來的軌跡區段。
大小和重複
當 結構模式 設為 Enum.TextureMode.Wrap 或 Enum.TextureMode.Static 時, 1> Class.Trail.TextureLength|TextureLength1> 屬性設定結構的長度,隨著結構在軌跡長度上重複。

當 結構模式 設為 Enum.TextureMode.Stretch 時,結構會在整個軌跡的總長度上重複 TextureLength 次。

移動
Texturemode 屬性也會影響軌跡的材質 移動 的方式,如下所示:
如果設為 Enum.TextureMode.Stretch,則會隨著軌跡的時間而伸展,如果軌跡的附件停止移動,則會縮小。
如果設為 Enum.TextureMode.Wrap,則材質會隨著軌跡長度變化而瓷磚,但材質會相對於附件保持不變。
如果設為 Enum.TextureMode.Static,則材質會隨著附件移動工具動而滾出,並且在其有效時間到達時仍會保持。這個設定適合於需要顯示「已貼上」的材質,例如爪子印記或輪胎軌跡。
方法
Clear
此方法立即清除所有軌跡的段落,並且對於清除歷史悠久的軌跡或對於特定操動作造成的情況有幫助。
呼叫此方法只會影響現有的區段。要清除現有軌跡區段 和 暫時防止新區段被畫出,切換軌跡的Enabled屬性為false至同時。