How to make a trigger to play audio?


👉 BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.

To be able to achieve this goal, we need your support by becoming a Patreon Paid Member 👈

 

Tweet
EpicDude2

I want to know how to make a trigger such as in a valve game where you walk into an invisible box and it triggers and event

Grindalf commented:

This could be done in so many ways and you have not described enough for me to know exactly what you want but I will take a guess.

;before main loop
SoundPivot=createpivot()

;inside main loop
if entitydistance(player,SoundPivot)<5 and channelplaying(SoundEffect)=false then SoundEffect=playmusic("Your sound file here")

This could also be done as a preloaded sound, a 3D sound and coded in so many other ways.
The way I have shown here is super over simplified but it will probably give you a good idea of where/how to start.

RemiD commented:

the difference between a 2d sound ( loadsound() ) and a 3d sound ( load3dsound() ), is that with a 2d sound, the sound is always the same volume, whereas with a 3d sound, the volume depends on the 'listener' 3d orientation and distance (attached to the camera), related to the source of the 3d sound (attached to an entity)...

but you have to code your own procedure to determine if the source of a 3d sound is in the same room / zone or if it is in another room / zone or behind a wall.

Reply To Topic (minimum 10 characters)

Please log in to reply