2
$\begingroup$

I'm trying to create my first maze game. I have a "looping" music triggered by an Always sensor and I would like to change this music for another one once the player goes through a door. How can I do that? I've tried with different logic controllers (Xor, Nor, Or, etc) but to no avail.

$\endgroup$
2
$\begingroup$

I have all my audio and audio logic setup on my camera, just so it is easy to keep track of it all.

To start I have a boolean game property called "sound_switcher", the empty checkbox means that it is FALSE. This is what is getting changed when the player goes near my cone object. That property in turn controls which sound file gets played.

The Near sensor detects when the player gets close to my cone (it has a game property of "prop" on it).
When that gets triggered it toggles the game property (booleans can only be TRUE or FALSE).

Now look at the other two sensors (Always and Property). The Sound actuator only plays when the always sensor is true (always) and the game property is FALSE (remember I have it set to false by default).

Notice the top "Nand" controller, it is the important. When the player is near the cone, and the game property is true, the Property sensor is no longer true, thus the "Nand" controller is TRUE, which activates the second sound actuator.
(The Nand controller activates when at least one connected sensor evaluates False, which in this case is the only one plugged in to it the Property sensor.)

logic bricks and game property

Now the logic above will toggle the audio, but if you want the second song to keep playing even when you leave the cone, then simply delete the bottom Nand controller (it is highlighted in orange.)

The blend file

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.