踪迹对象用于在两个附件之间创建踪迹效果。当附件移动通过空间时,在其定义的平面上会绘制一种材质。这常用于创建类似于追踪轨道、足迹、轮胎轨道和类似效果的效果。
请参阅踪迹获取更多信息。
代码示例
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。
在其生命时间内缩放踪迹的宽度。
属性
Attachment1
一个 Trail 开始在其段落位置的位置画出它的段落,并在其附件 Attachment0 和 Class.Trail.附件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
Class.Trail 是一个 2D 投射,存在在 3D 空间中,意味着它可能不会从每个角度都可见。 面部相机 属性,当设置为 true,确保尾迹总是面向 1> Class.Workspace.CurrentCamera|CurrentCamera1>,无论其方向。
改变此属性会立即影响所有现有和未来的尾迹段。
Lifetime
使用寿命 属性确定每个踪迹中的每个部分在何时消失之前,在秒后,它们会持续的时间。默认为 2 秒,但可以在 0.01 到 20 之间任意设置。
该效果的 Color 和 Transparency 属性也用于确定每个部分是如何绘制的。 两个属性都是序列,因此它们在交叉时间段中定义其值,然后在交叉时间段之间进行交叉。
如果踪轨迹的使用期改变,现有段落即将立即为新的使用期,这意味着如果它们存在更长时间,它们将被立即移除。
LightEmission
确定在什么程度上尾迹的颜色与它背后的颜色混合。它应该设置在 0 到 1 之间。一个值为 0 使用标准混合模式,一个值为 1 使用添加性混合模式。
这个属性不应与 LightInfluence ,它决定了尾迹受到的环境光的影响。
改变此属性会立即影响所有现有和未来的踪轨迹段落。
这个属性会导致 不 发生尾迹,因此环境会亮起。
LightInfluence
确定程度 to which the trail is influenced by the environment's lighting, clamped between 0 and 1. 当 0 时,尾迹将不受环境照明的影响。 当 1 时,它将完全受到照明作为一个 BasePart 的影响。
改变此属性会立即影响所有现有和未来的踪轨迹段落。
还参阅 LightEmission ,该参数指定了颜色踪迹的颜色与颜色之间的混合度。
LocalTransparencyModifier
MaxLength
此属性确定踪轨迹的最大长度,以格子计。默认值为 0,表示踪迹不会有最长长度,踪迹段落会在其 Lifetime 过期。
这个属性可以与 MinLength 属性一起使用,它确定要绘制的踪迹的最小长度。
MinLength
此属性确定踪轨迹的最小长度,以格子计。如果没有移动至少此值的尾轨迹的附件,否则,新的段落将不会创建,现有段落的 endpoints 将移动到当前段落的当前位置。
注意,改变此属性只会影响新段落,其余已经绘制的段落将保持其当前长度。
这个属性可以与 MaxLength 属性使用,该属性确定其最古老的段落在清除之前的最大尾巴长度。
Texture
展示在踪轨迹上的文本。如果此属性未设置,文本将以固定飞机呈现;这也是当文本设置为无效内容ID或与文本相关的图像尚未加载时发生的情况。
纹理的外观可以通过其他踪迹属性修改,包括 Color 和 Transparency 。
纹理的缩放取决于 Attachment0 和 Attachment1 之间的距离,还有 TextureMode 、 1> Class.Trail.TextureLength|toggle长度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 次。

移动
Texturermode 属性还影响踪轨迹的材质的 移动 如下:
如果设置为 Enum.TextureMode.Stretch ,该材质会根据踪轨迹的使用期展开展开,如果踪轨迹的附件停止移动,则会收缩。
如果设置为 Enum.TextureMode.Wrap,该材质会根据踪迹长度变换,但该材质对于附件的相对位置会保持不变。
如果设置为 Enum.TextureMode.Static,该材质会在附件移动工具动时滚出,并且在其生命时间到期时仍然保持在位置。此设置对于应该在渲染时出现“已打印”的踪迹材质,例如爪子印记或轮胎轨道。
WidthScale
此属性是一个 NumberSequence ,可以在其生命时间内缩放踪迹的宽度。值可以从 0 到 1 之间,作为距离交轨迹附件的倍增。例如,如果交轨迹附件的距离是 2 格,值为 0.5 ,踪轨迹宽度将为 1 格,并将在两个附件之间中心
方法
Clear
此方法立即清除所有跟踪段的残留,并且有助于清理长生命时间的踪迹,或者在特定操动作导致踪迹需要移除的情况下使用。
调用此方法只会影响现有段落。要清除现有踪迹段落 和 暂时不会绘制新段轨迹,切换跟踪的 Enabled 属性为false在同时切换。