Hello! I have a question regarding sound effects. I want to get the PHYSICAL position property of the sound that is being played. NOT the TIME position. I want to get the coordinates of the sound effect being played. Is there a way I can do this? I have looked but all people ask is about the time position. Thank you in advance!
Sounds are 3D only when placed under BaseParts or Attachements, you can get Parent’s position to get sound’s position
I guess you’re right… i just thought there was a better way to do this which is by actually finding the position at which the sound is playing, but i guess that wont be possible…
Guess I’ll have to deal with a few problems here and there but it should be alright
Sadly not possible, idk why you need that as sounds are usually played client-side and only distance from source is checked, but still good luck
Sound:FindFirstAncestorWhichIsA("BasePart").Position
If the sound doesn’t have a BasePart parent, you’ll get an error. In this case, it’d just be 0,0,0 in the world.
This function will correctly return the absolute position the sound is playing at, even in special cases such as BasePart.Attachment.BasePart.Sound
, or otherwise nil
if it has no positional value.
local function GetPositionFromSound(Sound: Sound): Vector3?
local Attachment = Sound:FindFirstAncestorWhichIsA("Attachment")
local BasePart = Sound:FindFirstAncestorWhichIsA("BasePart")
if Attachment then
if BasePart and BasePart:IsDescendantOf(Attachment) then
return BasePart.Position
end
return Attachment.WorldPosition
end
if BasePart then
return BasePart.Position
end
return nil
end
Besides from what others have said, you shouldn’t need to he checking the position of where the sound is playing, because you have to choose where to play it in the first place. If possible try rethinking how you structure whatever you’re making so that you just use the position as you’re playing the sound there.
If a sound is placed in an Attachment, it will emit sound from the attachment’s position. If it’s placed in a BasePart, it will play the sound from all its surfaces. Anywhere else will just play the sound globally, and it will sound the same anywhere you move your camera.