@@ -361,11 +361,6 @@ export default class Car {
361361 this . vehicle . setWheelForce ( this . maxForce , 1 ) ;
362362 this . vehicle . setWheelForce ( this . maxForce , 2 ) ;
363363 this . vehicle . setWheelForce ( this . maxForce , 3 ) ;
364- // If no engine sound is playing, start playing
365- if ( ! this . engineRunning ) {
366- this . engine . start ( ) ;
367- this . engineRunning = true ;
368- }
369364 }
370365
371366 // Reverse when pressing S or Arrow Down
@@ -374,11 +369,6 @@ export default class Car {
374369 this . vehicle . setWheelForce ( - this . maxForce , 1 ) ;
375370 this . vehicle . setWheelForce ( - this . maxForce , 2 ) ;
376371 this . vehicle . setWheelForce ( - this . maxForce , 3 ) ;
377- // If no engine sound is playing, start playing
378- if ( ! this . engineRunning ) {
379- this . engine . start ( ) ;
380- this . engineRunning = true ;
381- }
382372 }
383373
384374 // If car is not accelerating or decelerating, stop applying force to wheels
@@ -387,14 +377,6 @@ export default class Car {
387377 this . vehicle . setWheelForce ( 0 , 1 ) ;
388378 this . vehicle . setWheelForce ( 0 , 2 ) ;
389379 this . vehicle . setWheelForce ( 0 , 3 ) ;
390- // If the engine is playing, stop it
391- if ( this . engineRunning ) {
392- this . engine . stop ( ) ;
393- // Brief timeout to ensure the player has stopped
394- setTimeout ( ( ) => {
395- this . engineRunning = false ;
396- } , 200 ) ;
397- }
398380 }
399381
400382 // Steer left when pressing A or Arrow Left
@@ -536,6 +518,7 @@ export default class Car {
536518 this . engine . loop = true ;
537519 // Connect to gain node to control proximity audio
538520 this . engine . connect ( this . gainNode ) ;
521+ this . engine . start ( ) ;
539522 }
540523
541524 /**
0 commit comments