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
€59.85
List Price:  €85.51
You save:  €25.65
£51.73
List Price:  £73.90
You save:  £22.17
CA$95.82
List Price:  CA$136.90
You save:  CA$41.07
A$106.25
List Price:  A$151.80
You save:  A$45.54
S$89.55
List Price:  S$127.94
You save:  S$38.38
HK$549.41
List Price:  HK$784.91
You save:  HK$235.49
CHF 55.69
List Price:  CHF 79.57
You save:  CHF 23.87
NOK kr707.19
List Price:  NOK kr1,010.31
You save:  NOK kr303.12
DKK kr446.61
List Price:  DKK kr638.05
You save:  DKK kr191.43
NZ$116.25
List Price:  NZ$166.08
You save:  NZ$49.83
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,516.35
List Price:  ৳12,166.73
You save:  ৳3,650.38
₹6,003.27
List Price:  ₹8,576.47
You save:  ₹2,573.19
RM297.63
List Price:  RM425.20
You save:  RM127.57
₦107,153.99
List Price:  ₦153,083.69
You save:  ₦45,929.70
₨19,919.72
List Price:  ₨28,457.96
You save:  ₨8,538.24
฿2,269.14
List Price:  ฿3,241.77
You save:  ฿972.63
₺2,811.76
List Price:  ₺4,016.97
You save:  ₺1,205.21
B$387.45
List Price:  B$553.52
You save:  B$166.07
R1,248.46
List Price:  R1,783.60
You save:  R535.13
Лв117.07
List Price:  Лв167.26
You save:  Лв50.18
₩96,193.28
List Price:  ₩137,424.86
You save:  ₩41,231.58
₪233.41
List Price:  ₪333.46
You save:  ₪100.04
₱3,954.60
List Price:  ₱5,649.68
You save:  ₱1,695.07
¥10,275.65
List Price:  ¥14,680.13
You save:  ¥4,404.48
MX$1,307.51
List Price:  MX$1,867.95
You save:  MX$560.44
QR254.91
List Price:  QR364.18
You save:  QR109.26
P933.20
List Price:  P1,333.20
You save:  P400
KSh9,042.70
List Price:  KSh12,918.70
You save:  KSh3,876
E£3,464.86
List Price:  E£4,950.01
You save:  E£1,485.15
ብር9,474.89
List Price:  ብር13,536.14
You save:  ብር4,061.25
Kz63,827.73
List Price:  Kz91,186.39
You save:  Kz27,358.65
CLP$66,494.69
List Price:  CLP$94,996.49
You save:  CLP$28,501.80
CN¥501.68
List Price:  CN¥716.72
You save:  CN¥215.04
RD$4,210.88
List Price:  RD$6,015.80
You save:  RD$1,804.92
DA9,082.69
List Price:  DA12,975.83
You save:  DA3,893.13
FJ$156.86
List Price:  FJ$224.10
You save:  FJ$67.23
Q538.01
List Price:  Q768.63
You save:  Q230.61
GY$14,652.51
List Price:  GY$20,933.06
You save:  GY$6,280.54
ISK kr8,523.38
List Price:  ISK kr12,176.78
You save:  ISK kr3,653.40
DH629.71
List Price:  DH899.63
You save:  DH269.91
L1,186.83
List Price:  L1,695.54
You save:  L508.71
ден3,684.28
List Price:  ден5,263.48
You save:  ден1,579.20
MOP$566.28
List Price:  MOP$809
You save:  MOP$242.72
N$1,243.36
List Price:  N$1,776.31
You save:  N$532.94
C$2,575.19
List Price:  C$3,679
You save:  C$1,103.81
रु9,595.91
List Price:  रु13,709.03
You save:  रु4,113.12
S/248.18
List Price:  S/354.56
You save:  S/106.38
K288.69
List Price:  K412.43
You save:  K123.74
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,696.61
List Price:  ZK2,423.83
You save:  ZK727.22
L304.03
List Price:  L434.35
You save:  L130.32
Kč1,476.01
List Price:  Kč2,108.68
You save:  Kč632.67
Ft23,911.89
List Price:  Ft34,161.31
You save:  Ft10,249.42
SEK kr667.12
List Price:  SEK kr953.06
You save:  SEK kr285.94
ARS$87,889.56
List Price:  ARS$125,561.90
You save:  ARS$37,672.33
Bs481.93
List Price:  Bs688.51
You save:  Bs206.57
COP$281,336.43
List Price:  COP$401,926.41
You save:  COP$120,589.98
₡35,320.58
List Price:  ₡50,460.13
You save:  ₡15,139.55
L1,841.80
List Price:  L2,631.26
You save:  L789.45
₲542,795.68
List Price:  ₲775,455.63
You save:  ₲232,659.95
$U2,830.02
List Price:  $U4,043.06
You save:  $U1,213.04
zł254.68
List Price:  zł363.84
You save:  zł109.16
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.