Trail

顯示已棄用項目

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

軌跡 物件用於創建兩個附件之間的軌跡效果。隨著附件在空間移動,在定義的平面上繪製了紋理。這通常用於創建效果,以視覺化像箭頭軌跡、腳印、輪胎軌跡和類似效果的運動。

查看 軌跡 以獲得更多資訊。

範例程式碼

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.

Creating a Part with a Basic 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
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

概要

屬性

屬性

Attachment0

平行讀取

A Trail 開始在其 附件0Attachment1 位置繪製它的區域。當軌跡是 時,它記錄每一個框架的附件位置,並將這些位置連接到上一個框架的附件位置,創建一個由軌跡的 和 填充的多邊形,然後由軌跡的 填充。

在一個軌跡正在繪畫時變更軌跡的附件會移除已繪畫的所有軌跡段。

Attachment1

平行讀取

A Trail 開始在其 Attachment0附件1 位置繪製它的區域。當軌跡是 時,它記錄每一個框架的附件位置,並將這些位置連接到上一個框架的附件位置,創建一個由軌跡的 和 填充的多邊形,然後由軌跡的 填充。

在一個軌跡正在繪畫時變更軌跡的附件會移除已繪畫的所有軌跡段。

Brightness

平行讀取

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

平行讀取

在其生命週期內決定軌跡的顏色。如果 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.

Creating a Trail with a Color Gradient

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 之間任何地方設置。

軌跡的生命時間也被效果的 ColorTransparency 屬性用來決定每個區段是如何繪製。這兩個屬性都是順序,意味著它們在段落生命週期的某些關鍵點定義其值,然後在段落年齡時間之間互相插入值。

如果軌跡的生命週期發生變化,現有段落將立即以如果它們總是擁有新的生命週期一樣的行為,這意味著如果它們已存在超過新生命週期,它們將立即被移除。

LightEmission

平行讀取

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

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

即時變更此屬性會立即影響所有現有和未來的軌跡段。

此屬性不會 使軌跡照亮環境

LightInfluence

平行讀取

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

即時變更此屬性會立即影響所有現有和未來的軌跡段。

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

LocalTransparencyModifier

隱藏
未複製
平行讀取

MaxLength

平行讀取

此屬性決定軌跡的最大長度,以厘米為單位。其值預設為 0,意味著軌跡將沒有最大長度,軌跡段將在 Lifetime 到期。

此屬性可與 MinLength 屬性一起使用,決定軌跡在被繪製之前必須達到的最小長度。

MinLength

平行讀取

此屬性決定軌跡的最小長度,以厘米為單位。如果徑的附件之一至少沒有移動這個值,就不會創建新的區段,現有段的端點將移至附件的當前位置。

請注意,變更此屬性只會影響已繪製的 段;任何已繪製的舊段將保持其現有長度。

此屬性可與 MaxLength 屬性一起使用,決定最長軌跡長度,直到最舊的部分被刪除。

Texture

ContentId
平行讀取

要顯示在軌跡上的紋理內容ID。如果此屬性未設設定,軌跡將顯示為堅固的平面;這也會發生在紋理設置為無效的內容ID或紋理與相關的圖像尚未載入時。

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

紋理的縮放由 Attachment0Attachment1 之間的距離以及 TextureModeTextureLengthWidthScale 屬性決定。

範例程式碼

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.

Creating a Trail with a Paw Print Texture

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

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

運動

紋理模式 屬性也會影響軌跡紋理的 移動 如下:

  • 如果設為 Enum.TextureMode.Stretch,紋理將根據軌跡的生命時間伸展,如果軌跡的附件停止移動,縮小到內部。

  • 如果設為 Enum.TextureMode.Wrap,紋理將隨著軌跡長度變更而被瓷磚化,但紋理將維持與附件相對不動。

  • 如果設為 Enum.TextureMode.Static ,紋理將在附件移移動工具時展開,直到其使用期限到達為止。此設定非常適合在渲染時應該出現「印記」的軌跡紋理,例如爪印或輪胎軌跡。

Transparency

平行讀取

設置軌跡的區段透明度在其 Lifetime 上。此值是 NumberSequence ,意味著它可以是靜態值或在軌道段的使用期間可能會變化。

WidthScale

平行讀取

此屬性是 NumberSequence ,可以在其生命週期內擴展軌跡的寬度。值可介於 0 和 1之間,作為軌跡附件之間的距離乘數。例如,如果軌跡的附件距離是 2 個磚塊,這個屬性的值是 0.5,軌跡的寬度將是 1 個單位,軌跡將中心在兩個附件之間。

方法

Clear

()

這個方法立即清除所有軌跡的區段,對於具有更長生命期的軌跡或因特定行動作而需要移除軌跡來說,有用。

呼叫此方法只會影響現有的段落。要清除現有軌跡片段 暫時防止新軌跡片段被繪製,請同時切換軌跡的 Enabled 屬性至 false


返回

()

活動