fix sound issues

This commit is contained in:
LabyStudio
2022-02-13 08:10:28 +01:00
parent c955fdc7f9
commit b7b3439f0d
2 changed files with 25 additions and 18 deletions
+7 -3
View File
@@ -45,7 +45,7 @@ window.Player = class {
this.timeFovChanged = 0; this.timeFovChanged = 0;
this.distanceWalked = 0; this.distanceWalked = 0;
this.nextStepDistance = 0; this.nextStepDistance = 1;
} }
respawn() { respawn() {
@@ -248,6 +248,8 @@ window.Player = class {
let prevX = this.x; let prevX = this.x;
let prevZ = this.z; let prevZ = this.z;
let isSlow = this.onGround && this.sneaking;
let value = 0.16277136 / (prevSlipperiness * prevSlipperiness * prevSlipperiness); let value = 0.16277136 / (prevSlipperiness * prevSlipperiness * prevSlipperiness);
let friction; let friction;
@@ -275,6 +277,8 @@ window.Player = class {
this.motionY *= 0.98; this.motionY *= 0.98;
this.motionZ *= slipperiness; this.motionZ *= slipperiness;
// Step sound
if (!isSlow) {
let blockX = MathHelper.floor_double(this.x); let blockX = MathHelper.floor_double(this.x);
let blockY = MathHelper.floor_double(this.y - 0.2); let blockY = MathHelper.floor_double(this.y - 0.2);
let blockZ = MathHelper.floor_double(this.z); let blockZ = MathHelper.floor_double(this.z);
@@ -283,10 +287,9 @@ window.Player = class {
let distanceX = this.x - prevX; let distanceX = this.x - prevX;
let distanceZ = this.z - prevZ; let distanceZ = this.z - prevZ;
// Step sound
this.distanceWalked += Math.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.6; this.distanceWalked += Math.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.6;
if (this.distanceWalked > this.nextStepDistance && typeId !== 0) { if (this.distanceWalked > this.nextStepDistance && typeId !== 0) {
this.nextStepDistance++; this.nextStepDistance = this.distanceWalked + 1;
let block = Block.getById(typeId); let block = Block.getById(typeId);
let sound = block.getSound(); let sound = block.getSound();
@@ -297,6 +300,7 @@ window.Player = class {
} }
} }
} }
}
getBlockSlipperiness() { getBlockSlipperiness() {
return this.onGround ? 0.6 : 1.0; return this.onGround ? 0.6 : 1.0;
@@ -38,7 +38,9 @@ window.SoundManager = class {
} }
loadSound(path) { loadSound(path) {
let scope = this; if (!this.isCreated()) {
return;
}
// Create sound // Create sound
let sound = new THREE.PositionalAudio(this.audioListener); let sound = new THREE.PositionalAudio(this.audioListener);
@@ -47,6 +49,7 @@ window.SoundManager = class {
sound.setFilter(sound.context.createBiquadFilter()); sound.setFilter(sound.context.createBiquadFilter());
// Load sound // Load sound
let scope = this;
this.audioLoader.load(path, function (buffer) { this.audioLoader.load(path, function (buffer) {
sound.setBuffer(buffer); sound.setBuffer(buffer);
scope.scene.add(sound); scope.scene.add(sound);