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()

요약

속성

메서드

속성

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.

메서드

GetConnectedWires

매개 변수

pin: string

반환

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.


반환

SetDistanceAttenuation

void

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.

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

매개 변수

curve: Dictionary

반환

void

코드 샘플

Custom Distance Attenuation

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 -- Within a distance of 10 studs, listeners hear this emitter at full volume
curve[100] = 0.4 -- At a distance of 100 studs, listeners hear this emitter at 40% volume
curve[300] = 0 -- At any distance farther than 300 studs, listeners cannot hear this emitter
emitter:SetDistanceAttenuation(curve)
-- Replicate the rolloff curve from the old voice implementation
-- Default voice without the new audio API uses quadratic rolloff ranging from 7 to 80 studs
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

이벤트