AudioEmitter

แสดงที่เลิกใช้งานแล้ว

AudioEmitter emits audio streams into the world. It provides a single Input pin that can be connected to by one or more Wires. Any streams wired to an AudioEmitter get broadcasted into the world from the emitter's parent's position. If the parent is an Attachment, Camera, or PVInstance, the parent's world-position will be used. If the parent is not one of these classes, the AudioEmitter is effectively silent.

AudioEmitters are heard by AudioListeners in order to implement 3D spatialization.

ตัวอย่างโค้ด

Playing one asset from multiple 3d locations at once

local part1: BasePart = workspace.Speakers.Left
local part2: BasePart = workspace.Speakers.Right
local player: AudioPlayer = workspace.AudioPlayer
local leftEmitter = Instance.new("AudioEmitter")
local rightEmitter = Instance.new("AudioEmitter")
local toLeft = Instance.new("Wire")
local toRight = Instance.new("Wire")
leftEmitter.Parent = part1
rightEmitter.Parent = part2
toLeft.Parent = leftEmitter
toLeft.SourceInstance = player
toLeft.TargetInstance = leftEmitter
toRight.Parent = rightEmitter
toRight.SourceInstance = player
toRight.TargetInstance = rightEmitter
player:Play()

สรุป

คุณสมบัติ

วิธีการ

คุณสมบัติ

AngleAttenuation

BinaryString
การรักษาความปลอดภัยของ Roblox
อ่านพร้อมๆ กัน

Represents a volume-over-angle curve that affects how loudly a AudioListener will hear the AudioEmitter, based on the angle between them and the LookVector associated with the AudioEmitter.

This property is internal and can't be accessed by scripts; it exists to support replication. See SetAngleAttenuation() for usage details.

AudioInteractionGroup

อ่านพร้อมๆ กัน

If an AudioEmitter and an AudioListener share an interaction group, then the listener is capable of hearing the emitter.

DistanceAttenuation

BinaryString
การรักษาความปลอดภัยของ Roblox
อ่านพร้อมๆ กัน

Represents a volume-over-distance curve that affects how loudly a AudioListener will hear the AudioEmitter, based on the distance between them.

This property is internal and can't be accessed by scripts; it exists to support replication. See SetDistanceAttenuation() for usage details.

อ่านพร้อมๆ กัน

Controls how detailed the audio simulation should be for this AudioEmitter, similar to MeshPart.CollisionFidelity or MeshPart.RenderFidelity.

AudioEmitters and AudioListeners which disagree on the necessary level of detail will use the less-detailed option.

วิธีการ

GetAngleAttenuation

Returns a table mapping angle to volume. Keys are numbers between 0 and 180 (inclusive), while values are numbers between 0 and 1 (inclusive) describing how volume attenuates depending on direction. This method returns an empty table if the default angle attenuation curve is being used.


ส่งค่ากลับ

Table mapping angle to volume, as described above.

GetAudibilityFor

Calculates how audible this emitter is for a particular AudioListener. The resulting volume, ranging from 0 to 1, accounts for distance and angle attenuation on both the emitter and listener.

พารามิเตอร์

listener: AudioListener
ค่าเริ่มต้น: ""

ส่งค่ากลับ

GetConnectedWires

Instances

Returns an array of Wires that are connected to the specified pin. AudioEmitter has one "Input" pin.

พารามิเตอร์

pin: string
ค่าเริ่มต้น: ""

ส่งค่ากลับ

Instances

GetDistanceAttenuation

Returns a table mapping distance to volume. Keys are numbers greater than or equal to 0, while values are numbers between 0 and 1 (inclusive) describing how volume attenuates over distance. This method returns an empty table if the default distance attenuation curve is being used.


ส่งค่ากลับ

GetInputPins


ส่งค่ากลับ

GetInteractingListeners

Instances

Returns an array of AudioListeners that share an AudioInteractionGroup with the emitter.


ส่งค่ากลับ

Instances

GetOutputPins


ส่งค่ากลับ

SetAngleAttenuation

()

Sets a volume-over-angle curve that affects how loudly a AudioListener will hear the AudioEmitter, based on the angle between them and the LookVector associated with the AudioEmitter.

The curve is represented by a table mapping angle keys to volume values. Keys are expected to be unique numbers between 0 and 180 (inclusive), while values are expected to be numbers between 0 and 1 (inclusive). Tables containing up to 400 key-value pairs are supported.

The volume of the AudioEmitter from the perspective of a AudioListener at an angle a is determined by linearly interpolating between the volume levels for the points on the curve whose angle values are directly above and below a. If there is either no point below a or no point above a, the volume level of the other point is chosen. Essentially, the curve is a sequence of points connected by straight lines, and beyond its left and right endpoints the curve extends outward at their respective volume levels.

This volume will be multiplied with the volumes from all other attenuation curves (including the ones on the receiving AudioListener) to obtain the final audibility.

If the table is empty or nil, the AudioEmitter defaults to using an angle attenuation curve with the constant volume value of 1.

พารามิเตอร์

curve: Dictionary
ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

SetDistanceAttenuation

()

Sets a volume-over-distance curve that affects how loudly a AudioListener will hear the AudioEmitter, based on the distance between them.

The curve is represented by a table mapping distance keys to volume values. Keys are expected to be unique numbers greater than or equal to 0, while values are expected to be numbers between 0 and 1 (inclusive). Tables containing up to 400 key-value pairs are supported.

The volume of the AudioEmitter from the perspective of a AudioListener at a distance d is determined by linearly interpolating between the volume levels for the points on the curve whose distance values are directly above and below d. If there is either no point below d or no point above d, the volume level of the other point is chosen. Essentially, the curve is a sequence of points connected by straight lines, and beyond its left and right endpoints the curve extends outward infinitely at their respective volume levels.

This volume will be multiplied with the volumes from all other attenuation curves (including the ones on the receiving AudioListener) to obtain the final audibility.

If the table is empty or nil, the AudioEmitter defaults to using a distance attenuation curve determined by the inverse-square law.

พารามิเตอร์

curve: Dictionary
ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

ตัวอย่างโค้ด

การลดระยะทางที่กำหนดเอง

local Players = game:GetService("Players")
local emitterPart = Instance.new("Part")
emitterPart.Anchored = true
emitterPart.Position = Vector3.new(0, 0, 0)
emitterPart.Parent = workspace
local emitter: AudioEmitter = Instance.new("AudioEmitter")
emitter.Parent = emitterPart
local curve = {}
curve[10] = 1 -- ภายในระยะ 10 สตัด ผู้ฟังได้ยินเอมิตเตอร์นี้ที่ระดับเสียงเต็ม
curve[100] = 0.4 -- ในระยะ 100 สตัด ผู้ฟังได้ยินเอมิตเตอร์นี้ที่ระดับเสียง 40%
curve[300] = 0 -- ในระยะไกลมากกว่า 300 สตัด ผู้ฟังไม่สามารถได้ยินเอมิตเตอร์นี้
emitter:SetDistanceAttenuation(curve)
-- ทำซ้ำเส้นโค้งการลดลงจากการใช้งานเสียงเก่า
-- เสียงเริ่มต้นโดยไม่มี API เสียงใหม่ใช้การลดเสียงขั้นเท่าที่ 7 ถึง 80 สตัด
local MIN_DISTANCE = 7
local MAX_DISTANCE = 80
local CURVE_STEP_SIZE = 2
local voiceCurve = {}
for i = MIN_DISTANCE, MAX_DISTANCE, CURVE_STEP_SIZE do
voiceCurve[i] = ((i - MIN_DISTANCE) - (MAX_DISTANCE - MIN_DISTANCE)) ^ 2 / (MAX_DISTANCE - MIN_DISTANCE) ^ 2
end
voiceCurve[MAX_DISTANCE] = 0
local function setVoiceCurve(character)
local voiceEmitter: AudioEmitter = character:WaitForChild("AudioEmitter")
voiceEmitter:SetDistanceAttenuation(voiceCurve)
end
for _, player in Players:GetPlayers() do
if player.Character then
setVoiceCurve(player.Character)
end
player.CharacterAdded:Connect(setVoiceCurve)
end

อีเวนต์

WiringChanged

Event that fires after a Wire becomes connected or disconnected, and that Wire is now or was previously connected to a pin on the AudioEmitter and to some other wirable instance.

พารามิเตอร์

connected: boolean

Whether the instance got connected or disconnected.

pin: string

The pin on the AudioEmitter that the Wire targets.

wire: Wire

The Wire between the AudioEmitter and the other instance.

instance: Instance

The other instance that is or was connected through the Wire.