Document stub.png This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (April 2019)
Reason: Script descriptions could be reworded
Document.png Please expand this article or section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (April 2019)

3-dimensional sound (3D sound) is a type of manipulation of audio output to give the illusion that sound is coming from different directions. It has become possible in Scratch 3.0 due to several new Sound Blocks, mainly set [ v] effect to ()::sound and change [ v] effect by ()::sound.

This technique is only effective on devices using stereo speakers, headphones, or earphones.

Scripts

To make 3-dimensional sound, create the following scripts to the desired sprite that will play the sound:

when gf clicked
repeat until <(playing sound) = [0]>
  play sound [sound v] until done
end

when gf clicked
repeat until <(playing sound) = [0]>
  set volume to ((200) - (distance to [listener v]))
  set [pan left/right v] effect to ((x position) - ([x position v] of (listener v)))
end

If the sound has to repeat infinitely instead of the script repeating until something happens, the repeat until block should be changed to a forever block:

when gf clicked
forever
  play sound [sound v] until done
end

when gf clicked
forever
  set volume to ((200) - (distance to [listener v]))
  set [pan left/right v] effect to ((x position) - ([x position v] of (listener v)))
end

See Also