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
€60.09
List Price:  €85.84
You save:  €25.75
£52.05
List Price:  £74.36
You save:  £22.31
CA$96.36
List Price:  CA$137.67
You save:  CA$41.30
A$107.32
List Price:  A$153.33
You save:  A$46
S$89.91
List Price:  S$128.46
You save:  S$38.54
HK$549.41
List Price:  HK$784.91
You save:  HK$235.49
CHF 56.66
List Price:  CHF 80.95
You save:  CHF 24.28
NOK kr716.50
List Price:  NOK kr1,023.62
You save:  NOK kr307.11
DKK kr448.48
List Price:  DKK kr640.71
You save:  DKK kr192.23
NZ$117.79
List Price:  NZ$168.27
You save:  NZ$50.48
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,492.75
List Price:  ৳12,133.03
You save:  ৳3,640.27
₹6,137.45
List Price:  ₹8,768.17
You save:  ₹2,630.71
RM296.30
List Price:  RM423.30
You save:  RM127
₦107,233.07
List Price:  ₦153,196.67
You save:  ₦45,963.60
₨19,840.66
List Price:  ₨28,345.01
You save:  ₨8,504.35
฿2,267.23
List Price:  ฿3,239.04
You save:  ฿971.81
₺2,849.10
List Price:  ₺4,070.32
You save:  ₺1,221.21
B$380.31
List Price:  B$543.33
You save:  B$163.01
R1,241.04
List Price:  R1,773
You save:  R531.95
Лв117.57
List Price:  Лв167.97
You save:  Лв50.39
₩97,323.21
List Price:  ₩139,039.12
You save:  ₩41,715.90
₪239.28
List Price:  ₪341.84
You save:  ₪102.56
₱3,991.42
List Price:  ₱5,702.27
You save:  ₱1,710.85
¥10,340.17
List Price:  ¥14,772.31
You save:  ¥4,432.13
MX$1,300.63
List Price:  MX$1,858.13
You save:  MX$557.49
QR255.49
List Price:  QR365
You save:  QR109.51
P940.81
List Price:  P1,344.08
You save:  P403.26
KSh9,039.20
List Price:  KSh12,913.70
You save:  KSh3,874.50
E£3,393.81
List Price:  E£4,848.51
You save:  E£1,454.70
ብር9,702.55
List Price:  ብር13,861.38
You save:  ብር4,158.83
Kz63,827.73
List Price:  Kz91,186.39
You save:  Kz27,358.65
CLP$67,765.01
List Price:  CLP$96,811.31
You save:  CLP$29,046.30
CN¥502.78
List Price:  CN¥718.28
You save:  CN¥215.50
RD$4,270.18
List Price:  RD$6,100.53
You save:  RD$1,830.34
DA9,086.13
List Price:  DA12,980.75
You save:  DA3,894.61
FJ$157.78
List Price:  FJ$225.41
You save:  FJ$67.63
Q536.34
List Price:  Q766.24
You save:  Q229.89
GY$14,624.57
List Price:  GY$20,893.14
You save:  GY$6,268.57
ISK kr8,593.37
List Price:  ISK kr12,276.77
You save:  ISK kr3,683.40
DH633.02
List Price:  DH904.36
You save:  DH271.33
L1,173.74
List Price:  L1,676.84
You save:  L503.10
ден3,689.81
List Price:  ден5,271.38
You save:  ден1,581.57
MOP$565.17
List Price:  MOP$807.42
You save:  MOP$242.25
N$1,239.02
List Price:  N$1,770.11
You save:  N$531.08
C$2,573.19
List Price:  C$3,676.14
You save:  C$1,102.95
रु9,796.25
List Price:  रु13,995.24
You save:  रु4,198.99
S/247.41
List Price:  S/353.46
You save:  S/106.05
K294.93
List Price:  K421.35
You save:  K126.41
SAR262.66
List Price:  SAR375.25
You save:  SAR112.58
ZK1,620.47
List Price:  ZK2,315.06
You save:  ZK694.58
L304.43
List Price:  L434.92
You save:  L130.49
Kč1,471.73
List Price:  Kč2,102.56
You save:  Kč630.83
Ft23,769.43
List Price:  Ft33,957.78
You save:  Ft10,188.35
SEK kr671.61
List Price:  SEK kr959.49
You save:  SEK kr287.87
ARS$92,773.80
List Price:  ARS$132,539.68
You save:  ARS$39,765.88
Bs483
List Price:  Bs690.03
You save:  Bs207.02
COP$283,197.25
List Price:  COP$404,584.84
You save:  COP$121,387.59
₡35,430.68
List Price:  ₡50,617.43
You save:  ₡15,186.74
L1,830.90
List Price:  L2,615.69
You save:  L784.78
₲523,706.29
List Price:  ₲748,183.91
You save:  ₲224,477.62
$U2,803.39
List Price:  $U4,005.02
You save:  $U1,201.62
zł255.53
List Price:  zł365.06
You save:  zł109.53
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.