Adjust Volume Using Proximity

Create a 3D RPG Game with THREE.js Adding Sound to Your Game
1 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€63.43
List Price:  €90.62
You save:  €27.19
£54.59
List Price:  £77.99
You save:  £23.40
CA$99.28
List Price:  CA$141.83
You save:  CA$42.55
A$116.01
List Price:  A$165.73
You save:  A$49.72
S$94.28
List Price:  S$134.69
You save:  S$40.41
HK$543.06
List Price:  HK$775.84
You save:  HK$232.77
CHF 58.87
List Price:  CHF 84.10
You save:  CHF 25.23
NOK kr767.02
List Price:  NOK kr1,095.79
You save:  NOK kr328.77
DKK kr473.79
List Price:  DKK kr676.87
You save:  DKK kr203.08
NZ$125.70
List Price:  NZ$179.58
You save:  NZ$53.87
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,507.31
List Price:  ৳12,153.82
You save:  ৳3,646.51
₹6,064.15
List Price:  ₹8,663.45
You save:  ₹2,599.29
RM314.67
List Price:  RM449.55
You save:  RM134.88
₦109,818.50
List Price:  ₦156,890.30
You save:  ₦47,071.80
₨19,649.69
List Price:  ₨28,072.19
You save:  ₨8,422.50
฿2,418.11
List Price:  ฿3,454.60
You save:  ฿1,036.48
₺2,660.25
List Price:  ₺3,800.52
You save:  ₺1,140.27
B$428.02
List Price:  B$611.48
You save:  B$183.46
R1,380.99
List Price:  R1,972.93
You save:  R591.93
Лв124.09
List Price:  Лв177.28
You save:  Лв53.19
₩103,405.96
List Price:  ₩147,729.13
You save:  ₩44,323.17
₪266.03
List Price:  ₪380.06
You save:  ₪114.02
₱4,019.63
List Price:  ₱5,742.57
You save:  ₱1,722.94
¥10,164.37
List Price:  ¥14,521.16
You save:  ¥4,356.78
MX$1,457.30
List Price:  MX$2,081.95
You save:  MX$624.64
QR255.23
List Price:  QR364.64
You save:  QR109.40
P984.87
List Price:  P1,407.02
You save:  P422.14
KSh9,060.20
List Price:  KSh12,943.70
You save:  KSh3,883.50
E£3,615.05
List Price:  E£5,164.58
You save:  E£1,549.52
ብር9,268.87
List Price:  ብር13,241.81
You save:  ብር3,972.94
Kz64,110.84
List Price:  Kz91,590.84
You save:  Kz27,480
CLP$70,064.88
List Price:  CLP$100,096.98
You save:  CLP$30,032.10
CN¥514.39
List Price:  CN¥734.87
You save:  CN¥220.48
RD$4,403.52
List Price:  RD$6,291.02
You save:  RD$1,887.49
DA9,320.07
List Price:  DA13,314.96
You save:  DA3,994.89
FJ$163.41
List Price:  FJ$233.46
You save:  FJ$70.04
Q540.46
List Price:  Q772.13
You save:  Q231.66
GY$14,693.19
List Price:  GY$20,991.18
You save:  GY$6,297.98
ISK kr9,190.38
List Price:  ISK kr13,129.68
You save:  ISK kr3,939.30
DH667.53
List Price:  DH953.65
You save:  DH286.12
L1,242.28
List Price:  L1,774.76
You save:  L532.48
ден3,904.63
List Price:  ден5,578.29
You save:  ден1,673.65
MOP$560.34
List Price:  MOP$800.53
You save:  MOP$240.18
N$1,356.34
List Price:  N$1,937.71
You save:  N$581.37
C$2,576.76
List Price:  C$3,681.25
You save:  C$1,104.48
रु9,617.79
List Price:  रु13,740.29
You save:  रु4,122.49
S/257.69
List Price:  S/368.15
You save:  S/110.45
K284.83
List Price:  K406.91
You save:  K122.08
SAR262.79
List Price:  SAR375.44
You save:  SAR112.64
ZK1,958.87
List Price:  ZK2,798.51
You save:  ZK839.63
L315.69
List Price:  L451.01
You save:  L135.31
Kč1,596.70
List Price:  Kč2,281.10
You save:  Kč684.40
Ft25,930.49
List Price:  Ft37,045.14
You save:  Ft11,114.65
SEK kr697.66
List Price:  SEK kr996.71
You save:  SEK kr299.04
ARS$75,297.20
List Price:  ARS$107,572.04
You save:  ARS$32,274.83
Bs484.89
List Price:  Bs692.73
You save:  Bs207.84
COP$303,974.09
List Price:  COP$434,267.32
You save:  COP$130,293.22
₡35,531.06
List Price:  ₡50,760.83
You save:  ₡15,229.77
L1,791.47
List Price:  L2,559.35
You save:  L767.88
₲560,534.76
List Price:  ₲800,798.27
You save:  ₲240,263.50
$U2,949.26
List Price:  $U4,213.41
You save:  $U1,264.14
zł272.35
List Price:  zł389.09
You save:  zł116.73
Already have an account? Log In

Transcript

Often with three days useful that our sound appears to be coming from a particular place. I walk away, not sure how clear it'll be on the recording, but I walk away, I can no longer hear the sound of the fans. Walking walk towards them gets louder and louder. Again, you've got run away. This appears to none. So let's have a look at the code for that.

When we load it in our environment, we saved the fans in an array. So initially we set a volume to zero and then we have a for each method of the fans array. Which will get each fan in turn, we calculate the distance from the player object to the fan. And we set a temporary volume which is between one and zero based on the distance divided by 1000. And if the current temporary volume is greater than our stored temporary Well, our stored volume, then we set our volume to be our current temporary volume. And then at the end of going through all the fans, we've got a volume based on the nearest of those three fans.

And we set our fan volume to that level. And that allows us as we walking around to hear the fans ramp up in volume as we approach them, and as we run away from them, the volume will disappear virtually to zero

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.