October 28, 2020, 06:07:05 AM

Author Topic: [bb] DistantSound() by aab [ 1+ years ago ]  (Read 1196 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] DistantSound() by aab [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : DistantSound()
Author : aab
Posted : 1+ years ago

Description : EmitSound wasn't working for me so i developed this simple version which works rather well:

distantSound(soundHandle,cam,entity,range#=500,volume#=1,inview#=0.7)

soundhandle-The sound loaded with loadsound, that you wish to play

cam-the camera handle that you wish the sound to play to
entity-the emitting entity

range-the range apon which the sound can no longer be heard(ie has dissipated completely)[default is 500]

volume-The max starting volume. This also alters the dissipation of the sound: increasing the volume will cut the sound off before it fades completely [default is 1]

inview#- This determines the (percentage/100) of volume retained while within the cameras view: in other words if not in view, that much of the volume will be lost. [defaults to 0.7]

The sounds are therefore quiet from a distance, loud close up, and quieter when out of view


Code :
Code: BlitzBasic
  1. Function distantSound(soundHandle,cam,entity,range#=500,volume#=1,inview#=0.7)
  2.         If range#<1 range#=1
  3.         ;If Not EntityInView(entity,cam) ChannelVolume soundHandle,0.5
  4.        
  5. ;       dis#=Sqr(Abs(EntityX(entity)-EntityX(cam))*Abs(EntityX(entity)-EntityX(cam))+Abs(EntityY(entity)-EntityY(cam))*Abs(EntityY(entity)-EntityY(cam))+Abs(EntityZ(entity)-EntityZ(cam))*Abs(EntityZ(entity)-EntityZ(cam)))
  6. dis#=entitydistance(cam,entity)
  7.         If 1-dis#/range#>0 And 1-dis#/range#<1
  8.                 SoundVolume soundHandle,volume#*(1-dis#/range#)*((1-inview)+(Float#(EntityInView(entity,cam))*inview))
  9.                 PlaySound soundHandle
  10.  
  11.         EndIf
  12.        
  13. End Function
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. ;This one Checks for Co-ordinates rather than entities
  21. Function distantSoundCoOrd(soundHandle,x1,y1,z1,x2,y2,z2,range#=500,volume#=1,inview#=0.7)
  22.         If range#<1 range#=1
  23.         ;If Not EntityInView(entity,cam) ChannelVolume soundHandle,0.5
  24.        
  25.         dis#=Sqr(Abs(x2-x1)*Abs(x2-x1))+Abs(y2-y1)*Abs(y2-y1)+Abs(z2-z1)*Abs(z2-z1)
  26.  
  27.         If 1-dis#/range#>0 And 1-dis#/range#<1
  28.                 SoundVolume soundHandle,volume#*(1-dis#/range#)*((1-inview)+(Float#(EntityInView(entity,cam))*inview))
  29.                 PlaySound soundHandle
  30.  
  31.         EndIf
  32.        
  33. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal