Hi guys, I tried a very basic sound distance effect. For example, when obj_character moves away from the object_gun that has a gun_sound, sound comes to as low volume. Also moves away more, sound doesn't come. Okay that is working like this.
obj_gun (Step Event)
Okay it's enough for me but I have a problem. If i put only one obj_gun and one obj_character in the room, it is working but if I put two obj_character and one obj_gun in the room, it is not working healthy. The problem is exactly, if obj_gun has 2 obj_character both near and far, I want to hear gun_sound but no sound due to far object. How can i solve that?
obj_gun (Step Event)
GML:
if instance_exists(obj_character) and (distance_to_object(obj_character))>128{
audio_sound_gain(gun_sound,0,false)
}
if instance_exists(obj_character) and (distance_to_object(obj_character))<128 and 96 < (distance_to_object(obj_character)){
audio_sound_gain(gun_sound,0.25,false)
}
if instance_exists(obj_character) and (distance_to_object(obj_character))<96 and 64 < (distance_to_object(obj_character)){
audio_sound_gain(gun_sound,0.5,false)
}
if instance_exists(obj_character) and (distance_to_object(obj_character))<64 and 32 < (distance_to_object(obj_character)){
audio_sound_gain(gun_sound,0.75,false)
}
if instance_exists(obj_character) and (distance_to_object(obj_character))<32 and 0 < (distance_to_object(obj_character)){
audio_sound_gain(gun_sound,1,false)
}