Beam

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

一个 光束 对象连接两个 Attachments 通过在其间绘制纹理。

要显示,光束必须是 Workspace 的子孙,其 Attachment0Attachment1 属性设置为 Attachments 也从 Workspace 降级。

光束的外观可以使用以下属性范围进行自定义。还请参阅光束指南的视觉示例。

梁曲率

光束配置为使用由四个控制点形成的立方体贝扎尔曲线。这意味着它们不受限于直线,光束的弯曲度可以通过修改 CurveSize0 , CurveSize1 和光束的 Attachments 来修改。

Beam curvature diagram

代码示例

This code sample demonstrates how a Beam effect can be created from scratch by creating a Beam, setting all of its properties and configuring it's Attachments.

Creating a Beam From Scratch

-- create attachments
local att0 = Instance.new("Attachment")
local att1 = Instance.new("Attachment")
-- parent to terrain (can be part instead)
att0.Parent = workspace.Terrain
att1.Parent = workspace.Terrain
-- position attachments
att0.Position = Vector3.new(0, 10, 0)
att1.Position = Vector3.new(0, 10, 10)
-- create beam
local beam = Instance.new("Beam")
beam.Attachment0 = att0
beam.Attachment1 = att1
-- appearance properties
beam.Color = ColorSequence.new({ -- a color sequence shifting from white to blue
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 255)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 255, 255)),
})
beam.LightEmission = 1 -- use additive blending
beam.LightInfluence = 0 -- beam not influenced by light
beam.Texture = "rbxasset://textures/particles/sparkles_main.dds" -- a built in sparkle texture
beam.TextureMode = Enum.TextureMode.Wrap -- wrap so length can be set by TextureLength
beam.TextureLength = 1 -- repeating texture is 1 stud long
beam.TextureSpeed = 1 -- slow texture speed
beam.Transparency = NumberSequence.new({ -- beam fades out at the end
NumberSequenceKeypoint.new(0, 0),
NumberSequenceKeypoint.new(0.8, 0),
NumberSequenceKeypoint.new(1, 1),
})
beam.ZOffset = 0 -- render at the position of the beam without offset
-- shape properties
beam.CurveSize0 = 2 -- create a curved beam
beam.CurveSize1 = -2 -- create a curved beam
beam.FaceCamera = true -- beam is visible from every angle
beam.Segments = 10 -- default curve resolution
beam.Width0 = 0.2 -- starts small
beam.Width1 = 2 -- ends big
-- parent beam
beam.Enabled = true
beam.Parent = att0

概要

属性

方法

属性

Attachment0

读取并联

Attachment发出的光束。这个附件是光束的立方体贝扎尔曲线的第一个控制点;其方向,与CurveSize0属性一起,决定了第二个控制点的位置。请参阅光束获取更多详情。

对于 Attachment ,在光束结束处,请参阅 Attachment1

Attachment1

读取并联

光束将在 Attachment 结束。这个附件是梁的立方体贝扎尔曲线上的第四个和最后一个控制点;其方向,与 CurveSize1 属性一起,决定了第三个控制点的位置。请参阅光束获取更多详情。

对于从哪里产生光束的 Attachment,请参阅 Attachment0

Brightness

读取并联

LightInfluence 小于 1 时,将光束发出的光放大到 1 倍。此属性默认为 1,可以设置为 0 到 10000 范围内的任何数字。增加 LightInfluence 的值会减少这个属性的效果。

读取并联

决定光束在其 Segments 的颜色。如果 Texture 被设置,这种颜色将应用于光束的纹理。如果没有设置Texture,那么Beam将以这个属性的颜色显示为粗线。

该属性是 ColorSequence ,允许颜色配置在光束长度上变化。考虑以下 ColorSequence ,当应用于光束时,将产生图像的结果。


local colorSequence = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)), -- 红色
ColorSequenceKeypoint.new(0.5, Color3.fromRGB(0, 188, 203)), -- 蓝绿色
ColorSequenceKeypoint.new(1, Color3.fromRGB(196, 0, 255)), -- 紫色
}
)

注意,光束的颜色也取决于 Segments 的数量,Beam 有。光束的每个部分只能显示两种颜色之间的过渡。因此,一个 Beam 需要至少有 n-1 个段落,以便颜色显示正确,其中 nColorSequenceKeypointsColorSequence 中的数量。

CurveSize0

读取并联

确定,以及Attachment0 ,光束的贝扎曲线中第二个控制点的位置。请参阅光束获取更多细节。

这一点的位置可以由以下方程式确定:


local controlPoint2 = Beam.Attachment0.WorldPosition + (Beam.Attachment0.CFrame.RightVector * Beam.CurveSize0)

CurveSize1

读取并联

确定,以及Attachment1 ,光束的贝扎曲线中第三个控制点的位置。请参阅光束获取更多细节。

这一点的位置可以由以下方程式确定:


local controlPoint3 = Beam.Attachment1.WorldPosition - (Beam.Attachment1.CFrame.RightVector * Beam.CurveSize1)

Enabled

读取并联

决定光束是否可见。

当此属性设置为 false 时,光束的 Segments 不会显示。

FaceCamera

读取并联

A Beam 是在 3D 空间中存在的 2D 投影,这意味着它可能不能从每个角度看到。当 面镜 属性设置为 true 时,确保光束总是面向 CurrentCamera ,无论其方向如何。

LightEmission

读取并联

决定光束的颜色与它后面的颜色融合到什么程度。它应该设置在 0 到 1 之间。值为 0 的值使用普通混合模式,值为 1 的值使用积累混合。

该属性不应与 LightInfluence 混淆,该属性决定了光束是如何受到环境光影响的。

此属性不会 使光束照亮环境

LightInfluence

读取并联

决定光束是否受环境照明的影响程度,范围为 0 到 1。当 0 时,光束将不受环境照明的影响。当 1 时,将完全受到照明影响,正如 BasePart 将是。

还请参阅LightEmission,该文件规定了光束的颜色与背后颜色的融合程度。

LocalTransparencyModifier

隐藏
未复制
读取并联

Segments

读取并联

rather than being a perfect curve, 光束由直段组成。段数越多,曲线的分辨率越高。 属性设置了光束由多少个直段组成,默认值为 10。

请注意,ColorTransparency 属性需要一定数量的段来正确显示。这是因为每个分段只能显示两种颜色或透明度之间的过渡。因此,需要至少 Beam 显示正确的段数 n-1 ,其中 n 是与光束的 ColorTransparency 相关的键点数量。

Texture

ContentId
读取并联

要显示在光束上的纹理内容ID。如果此属性未设置,光束将显示为坚固的线条;这也发生在将材质设置为无效内容ID或图像与材质相关的图像尚未加载时。

纹理的外观可以通过其他光束属性,包括 ColorTransparency 进行进一步修改。

纹理的缩放由 TextureModeTextureLengthWidth0Width1 属性决定。

TextureLength

读取并联

设置光束的纹理长度,取决于 TextureMode

TextureMode

读取并联

这个属性,以及 TextureLength ,决定了光束的 Texture 重复方式。

当设置为 Enum.TextureMode.WrapEnum.TextureMode.Static 时,纹理重复将等于光束的总长(在 studs)除以其 TextureLength

TextureMode diagram with Wrap mode

当设置为 Enum.TextureMode.Stretch 时,纹理将在整个光束长度上重复 TextureLength 次。

TextureMode diagram with Stretch mode

TextureSpeed

读取并联

决定图像 Texture 在光束上移动的速度。当此属性为正值时,光束的纹理将从 Attachment0 移至 Attachment1 。通过将此属性设置为负数来反转该方向。

Transparency

读取并联

确定光束在其各个部分的透明度。该属性是 NumberSequence ,允许透明度被配置为在光束长度上变化。

考虑以下 NumberSequence ,当应用于光束时,将产生图像的结果。


local numberSequence = NumberSequence.new({
NumberSequenceKeypoint.new(0, 0), -- 不透明
NumberSequenceKeypoint.new(0.5, 1), -- 透明
NumberSequenceKeypoint.new(1, 0), -- 不透明
}
)

请注意,光束的透明度也取决于 Segments 的数量。光束的每个部分只能显示两个透明度之间的过渡。因此,光束需要至少有 n-1 个部分才能正确显示,其中 nNumberSequenceKeypointsNumberSequence 中的数量。

Width0

读取并联

在其起源处的光束宽度(Attachment0),以学分计。光束的宽度将在其末端变为Width1学分(Attachment1)。

Width1

读取并联

在其末端的光束宽度(Attachment1),以点为单位。光束的宽度将从其起源的 Width0 点线性变化为 Attachment0 点。

ZOffset

读取并联

光束显示与 CurrentCamera 相对抵消的距离,以螺柱计算。当 0 时,光束将显示在 Attachment0Attachment1 之间的标准位置。 ZOffset 可以是正的或负的。

该属性特别有用于避免在使用多个 Beams 之间的相同 Attachments 时发生“Z‑战斗”。

代码示例

This code sample uses the Beam.ZOffset property to layer multiple beams between the same attachments.

Layering Beams

-- Create beams
local beam1 = Instance.new("Beam")
beam1.Color = ColorSequence.new(Color3.new(1, 0, 0))
beam1.FaceCamera = true
beam1.Width0 = 3
beam1.Width1 = 3
local beam2 = Instance.new("Beam")
beam2.Color = ColorSequence.new(Color3.new(0, 1, 0))
beam2.FaceCamera = true
beam2.Width0 = 2
beam2.Width1 = 2
local beam3 = Instance.new("Beam")
beam3.Color = ColorSequence.new(Color3.new(0, 0, 1))
beam3.FaceCamera = true
beam3.Width0 = 1
beam3.Width1 = 1
-- Layer beams
beam1.ZOffset = 0
beam2.ZOffset = 0.01
beam3.ZOffset = 0.02
-- Create attachments
local attachment0 = Instance.new("Attachment")
attachment0.Position = Vector3.new(0, -10, 0)
attachment0.Parent = workspace.Terrain
local attachment1 = Instance.new("Attachment")
attachment1.Position = Vector3.new(0, 10, 0)
attachment1.Parent = workspace.Terrain
-- Connect beams
beam1.Attachment0 = attachment0
beam1.Attachment1 = attachment1
beam2.Attachment0 = attachment0
beam2.Attachment1 = attachment1
beam3.Attachment0 = attachment0
beam3.Attachment1 = attachment1
-- Parent beams
beam1.Parent = workspace
beam2.Parent = workspace
beam3.Parent = workspace

方法

SetTextureOffset

()

光束的纹理周期的抵消表示其纹理动画的进度。该方法设置了光束的纹理周期当前偏移;因此,可以通过传递 0 作为 offset 参数来重置周期。

注释

  • 给定的 offset 参数期望为 0 到 1 之间的值,但更高的值也可以使用。
  • 纹理周期在 0 和 1 结束,这意味着当偏移为 0 或 1 时,纹理的位置相同。
  • 如果 Texture 属性未设置,该方法无做任何事情。
  • 增加抵消将在反向方向对 TextureSpeed 属性进行作用,意味着它将在 TextureSpeed 大于 0 时将纹理向相反的方向移动到纹理动画的方向。

参数

offset: number

纹理周期的预期偏移。

默认值:0

返回

()

活动