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.66
List Price:  €85.23
You save:  €25.57
£51.48
List Price:  £73.55
You save:  £22.06
CA$95.04
List Price:  CA$135.78
You save:  CA$40.73
A$97.40
List Price:  A$139.15
You save:  A$41.75
S$89.13
List Price:  S$127.34
You save:  S$38.20
HK$548.38
List Price:  HK$783.44
You save:  HK$235.05
CHF 54.69
List Price:  CHF 78.14
You save:  CHF 23.44
NOK kr649
List Price:  NOK kr927.19
You save:  NOK kr278.18
DKK kr445.82
List Price:  DKK kr636.92
You save:  DKK kr191.09
NZ$118.83
List Price:  NZ$169.77
You save:  NZ$50.93
د.إ257.03
List Price:  د.إ367.21
You save:  د.إ110.17
৳8,589.53
List Price:  ৳12,271.28
You save:  ৳3,681.75
₹6,640.63
List Price:  ₹9,487.03
You save:  ₹2,846.39
RM277.86
List Price:  RM396.96
You save:  RM119.10
₦96,246.74
List Price:  ₦137,501.24
You save:  ₦41,254.50
₨19,509.71
List Price:  ₨27,872.21
You save:  ₨8,362.50
฿2,276.38
List Price:  ฿3,252.11
You save:  ฿975.73
₺3,162.26
List Price:  ₺4,517.71
You save:  ₺1,355.44
B$346.87
List Price:  B$495.55
You save:  B$148.68
R1,172.75
List Price:  R1,675.43
You save:  R502.68
Лв116.66
List Price:  Лв166.66
You save:  Лв50
₩103,139.89
List Price:  ₩147,349.02
You save:  ₩44,209.12
₪206.52
List Price:  ₪295.04
You save:  ₪88.52
₱4,299.94
List Price:  ₱6,143.03
You save:  ₱1,843.09
¥10,958.82
List Price:  ¥15,656.13
You save:  ¥4,697.31
MX$1,223.48
List Price:  MX$1,747.90
You save:  MX$524.42
QR255.02
List Price:  QR364.33
You save:  QR109.31
P946.32
List Price:  P1,351.94
You save:  P405.62
KSh9,041.30
List Price:  KSh12,916.70
You save:  KSh3,875.40
E£3,752.40
List Price:  E£5,360.81
You save:  E£1,608.40
ብር10,988.43
List Price:  ብር15,698.43
You save:  ብር4,710
Kz63,908.98
List Price:  Kz91,302.46
You save:  Kz27,393.48
CLP$63,054.05
List Price:  CLP$90,081.08
You save:  CLP$27,027.02
CN¥477.90
List Price:  CN¥682.75
You save:  CN¥204.84
RD$4,163.10
List Price:  RD$5,947.54
You save:  RD$1,784.44
DA9,266.05
List Price:  DA13,237.78
You save:  DA3,971.73
FJ$153.39
List Price:  FJ$219.13
You save:  FJ$65.74
Q534.82
List Price:  Q764.07
You save:  Q229.24
GY$14,645.56
List Price:  GY$20,923.13
You save:  GY$6,277.56
ISK kr8,579.37
List Price:  ISK kr12,256.77
You save:  ISK kr3,677.40
DH646.28
List Price:  DH923.30
You save:  DH277.02
L1,200.31
List Price:  L1,714.81
You save:  L514.49
ден3,675.65
List Price:  ден5,251.15
You save:  ден1,575.50
MOP$564.87
List Price:  MOP$807
You save:  MOP$242.12
N$1,166.03
List Price:  N$1,665.83
You save:  N$499.80
C$2,573.69
List Price:  C$3,676.87
You save:  C$1,103.17
रु10,624.73
List Price:  रु15,178.84
You save:  रु4,554.10
S/245.50
List Price:  S/350.73
You save:  S/105.23
K304.07
List Price:  K434.40
You save:  K130.33
SAR262.47
List Price:  SAR374.98
You save:  SAR112.50
ZK1,321.46
List Price:  ZK1,887.88
You save:  ZK566.42
L310.08
List Price:  L442.99
You save:  L132.91
Kč1,455.20
List Price:  Kč2,078.95
You save:  Kč623.74
Ft21,785.61
List Price:  Ft31,123.64
You save:  Ft9,338.02
SEK kr647.31
List Price:  SEK kr924.77
You save:  SEK kr277.46
ARS$97,447.40
List Price:  ARS$139,216.54
You save:  ARS$41,769.14
Bs483.72
List Price:  Bs691.06
You save:  Bs207.33
COP$253,241.34
List Price:  COP$361,788.85
You save:  COP$108,547.51
₡31,826.91
List Price:  ₡45,468.96
You save:  ₡13,642.05
L1,862.75
List Price:  L2,661.18
You save:  L798.43
₲435,586.79
List Price:  ₲622,293.52
You save:  ₲186,706.72
$U2,791.86
List Price:  $U3,988.55
You save:  $U1,196.68
zł253.81
List Price:  zł362.60
You save:  zł108.79
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.