踪迹 对象用于创建两个附件之间的踪迹效果。当附件在空间移动时,在其定义的平面上绘制了纹理。这通常用于创建效果,可以视觉化像追踪轨道、脚印、轮胎轨道和类似效果的运动。
请参阅踪迹获取更多信息。
代码示例
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
一个 Trail 开始在其 附件0 和 Attachment1 位置绘制其段。当踪迹是 Enabled 时,它记录每个框架的附件位置,并将这些位置连接到上一框架的附件位置,创建一个由踪轨迹的 Color 和 Texture 填充的多边形。
在踪迹绘制时更改踪迹的附件将移除踪迹已绘制的所有部分。
Attachment1
一个 Trail 开始在其 Attachment0 和 Attachment1 位置绘制其段。当踪迹是 Enabled 时,它记录每个框架的附件位置,并将这些位置连接到上一框架的附件位置,创建一个由踪轨迹的 Color 和 Texture 填充的多边形。
在踪迹绘制时更改踪迹的附件将移除踪迹已绘制的所有部分。
Brightness
当 LightInfluence 小于 1 时,将发射到踪迹的光放大。此属性默认为 1,可以设置为 0 到 10000 范围内的任何数字。增加 LightInfluence 的值会减少这个属性的效果。
Color
决定了踪迹在其生命周期内的颜色。如果 Texture 被设置,这种颜色将渗透到纹理中。
该属性是 ColorSequence ,允许颜色配置在踪轨迹长度上变化。如果在绘制一些踪迹段之后颜色发生变化,所有旧段都将被更新以匹配新颜色。
代码示例
这个例子创建了一个渐变颜色的 Trail,意味着尾迹一端的颜色与另一端的颜色不同,两种颜色在靠近中间尾迹的时候会融合在一起。
local TweenService = game:GetService("TweenService")
-- 创建一个父部件
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
-- 在零件上创建附件
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
-- 创建带颜色渐变的新踪迹
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
-- 中途部分显示踪迹
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,这意味着踪迹的最大长度不会超过 2 和踪迹段将在其 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。