7

Adding Sound and Music to Your Game

Godot 4 fixed some audio issues, such as popping, resampling behavior, and performing sound operations simultaneously.

In this chapter, we are going to use the AudioStreamPlayer node to play constant music no matter where the player is located. We will also set up a repeated gunshot SFX to show off Godot 4’s built-in polyphonic support.

We will use the AudioStreamPlayer2D node to see how to create directional sound. When the player comes close to an object, they will be able to hear it. In the last recipe, we will use the AudioStreamPlayer3D node to create directional sound in a 3D environment.

In this chapter, we will cover the following recipes:

  • Working with AudioStreamPlayer
  • Exploring directional sound ...

Get Godot 4 Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.