軌跡 物件用於創建兩個附件之間的軌跡效果。隨著附件在空間移動,在定義的平面上繪製了紋理。這通常用於創建效果,以視覺化像箭頭軌跡、腳印、輪胎軌跡和類似效果的運動。
查看 軌跡 以獲得更多資訊。
範例程式碼
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 一起,決定軌跡將在哪裡開始繪製其段落。
與 Attachment0 一起,決定軌跡將在哪裡開始繪製其段落。
當 LightInfluence 小於 1 時,縮放從軌跡發出的光。
在其生命週期內的軌跡顏色。
決定是否繪製軌跡。
決定軌跡是否會始終面向相攝影機,無論其方向如何。
決定每個軌跡區段的持續時間,以秒為單位。
決定徑径的顏色與背後顏色的融合程度。
決定軌跡受環境燈光影響的程度。
設置軌跡的最大長度。
設置軌跡的最小長度。
要顯示在軌跡上的紋理內容ID。
設置軌跡的紋理長度,取決於 TextureMode 。
決定 Texture 的縮放、重複和移動方式,與軌跡附件一起進行。
設置軌跡的區段透明度在其 Lifetime 上。
在其生命週期內擴展軌跡的寬度。
屬性
Attachment0
A Trail 開始在其 附件0 和 Attachment1 位置繪製它的區域。當軌跡是 時,它記錄每一個框架的附件位置,並將這些位置連接到上一個框架的附件位置,創建一個由軌跡的 和 填充的多邊形,然後由軌跡的 填充。
在一個軌跡正在繪畫時變更軌跡的附件會移除已繪畫的所有軌跡段。
Attachment1
A Trail 開始在其 Attachment0 和 附件1 位置繪製它的區域。當軌跡是 時,它記錄每一個框架的附件位置,並將這些位置連接到上一個框架的附件位置,創建一個由軌跡的 和 填充的多邊形,然後由軌跡的 填充。
在一個軌跡正在繪畫時變更軌跡的附件會移除已繪畫的所有軌跡段。
Brightness
當 LightInfluence 小於 1 時,縮放從軌跡發出的光。此屬性的值為預設值為 1,可設為 0 到 10000 範圍內的任何數字。增加 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 時自然清除。若要強制清理現有的區段,請同時呼叫 Clear() 方法。
FaceCamera
A Trail 是在 3D 空間中存在的 2D 投影,意味著它可能不能從每個角度看到。當 面相機 屬性設為 true 時,確保軌跡總是面向 CurrentCamera,無論其方向如何。
立即變更此屬性會立即影響所有現有和未來的軌跡段。
Lifetime
生命時間 屬性決定在軌跡消失之前,每個區段會持續多久,以秒為單位。預設為 2 秒,但可以在 0.01 和 20 之間任何地方設置。
軌跡的生命時間也被效果的 Color 和 Transparency 屬性用來決定每個區段是如何繪製。這兩個屬性都是順序,意味著它們在段落生命週期的某些關鍵點定義其值,然後在段落年齡時間之間互相插入值。
如果軌跡的生命週期發生變化,現有段落將立即以如果它們總是擁有新的生命週期一樣的行為,這意味著如果它們已存在超過新生命週期,它們將立即被移除。
LightEmission
決定徑径的顏色與背後顏色的融合程度。應該設置在 0 到 1 之間。0的值使用普通混合模式,1的值使用添加混合模式。
此屬性不應與 LightInfluence 混淆,它決定軌跡如何受到環境光的影響。
即時變更此屬性會立即影響所有現有和未來的軌跡段。
此屬性不會 使軌跡照亮環境 。
LightInfluence
決定軌跡受環境燈光影響的程度,介於 0 和 1 之間。當 0 時,步道將不受環境燈光的影響。當 1 時,燈光的影響將完全像 BasePart 一樣。
即時變更此屬性會立即影響所有現有和未來的軌跡段。
也可以參考 LightEmission 指定軌跡顏色與背後顏色的融合程度。
LocalTransparencyModifier
MaxLength
此屬性決定軌跡的最大長度,以厘米為單位。其值預設為 0,意味著軌跡將沒有最大長度,軌跡段將在 Lifetime 到期。
此屬性可與 MinLength 屬性一起使用,決定軌跡在被繪製之前必須達到的最小長度。
MinLength
此屬性決定軌跡的最小長度,以厘米為單位。如果徑的附件之一至少沒有移動這個值,就不會創建新的區段,現有段的端點將移至附件的當前位置。
請注意,變更此屬性只會影響已繪製的 新 段;任何已繪製的舊段將保持其現有長度。
此屬性可與 MaxLength 屬性一起使用,決定最長軌跡長度,直到最舊的部分被刪除。
Texture
要顯示在軌跡上的紋理內容ID。如果此屬性未設設定,軌跡將顯示為堅固的平面;這也會發生在紋理設置為無效的內容ID或紋理與相關的圖像尚未載入時。
紋理的外觀可以進一步修改其他軌跡特性,包括 Color 和 Transparency 。
紋理的縮放由 Attachment0 和 Attachment1 之間的距離以及 TextureMode、TextureLength 和 WidthScale 屬性決定。
範例程式碼
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 時,TextureLength 屬性將紋理長度設為在軌跡道長度上重複的長度。

當 紋理模式 設為 Enum.TextureMode.Stretch 時,紋理將在整個軌跡長度上重複 TextureLength 次。

運動
紋理模式 屬性也會影響軌跡紋理的 移動 如下:
如果設為 Enum.TextureMode.Stretch,紋理將根據軌跡的生命時間伸展,如果軌跡的附件停止移動,縮小到內部。
如果設為 Enum.TextureMode.Wrap,紋理將隨著軌跡長度變更而被瓷磚化,但紋理將維持與附件相對不動。
如果設為 Enum.TextureMode.Static ,紋理將在附件移移動工具時展開,直到其使用期限到達為止。此設定非常適合在渲染時應該出現「印記」的軌跡紋理,例如爪印或輪胎軌跡。
WidthScale
此屬性是 NumberSequence ,可以在其生命週期內擴展軌跡的寬度。值可介於 0 和 1之間,作為軌跡附件之間的距離乘數。例如,如果軌跡的附件距離是 2 個磚塊,這個屬性的值是 0.5,軌跡的寬度將是 1 個單位,軌跡將中心在兩個附件之間。
方法
Clear
這個方法立即清除所有軌跡的區段,對於具有更長生命期的軌跡或因特定行動作而需要移除軌跡來說,有用。
呼叫此方法只會影響現有的段落。要清除現有軌跡片段 和 暫時防止新軌跡片段被繪製,請同時切換軌跡的 Enabled 屬性至 false。