Skip to content

Commit 8a7d033

Browse files
author
Picoseconds
committed
Add visual feedback for crouching
1 parent 8ef1303 commit 8a7d033

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

src/client/scripts/EventHandler.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,23 @@ class EventHandler {
108108
_this.gameState === "gameLock"
109109
) {
110110
_this.game.socket.emit("move", _this.controls[z.code], true);
111-
if (_this.controls[z.code] === "sprint") {
112-
var to = {
113-
fov: _this.game.fov + 10,
114-
};
115-
new TWEEN.Tween(_this.game.camera)
116-
.to(to, 200)
117-
.easing(TWEEN.Easing.Quadratic.Out)
118-
.onUpdate(function () {
119-
return _this.game.camera.updateProjectionMatrix();
120-
})
121-
.start();
111+
switch (_this.controls[z.code]) {
112+
case "sprint":
113+
var to = {
114+
fov: _this.game.fov,
115+
};
116+
new TWEEN.Tween(_this.game.camera)
117+
.to(to, 200)
118+
.easing(TWEEN.Easing.Quadratic.Out)
119+
.onUpdate(function () {
120+
return _this.game.camera.updateProjectionMatrix();
121+
})
122+
.start();
123+
break;
124+
125+
case "sneak":
126+
_this.game.headHeight = 16.7;
127+
break;
122128
}
123129
}
124130
});
@@ -127,17 +133,23 @@ class EventHandler {
127133
delete _this.keys[z.code];
128134
if (_this.controls[z.code] !== undefined) {
129135
_this.game.socket.emit("move", _this.controls[z.code], false);
130-
if (_this.controls[z.code] === "sprint") {
131-
var to = {
132-
fov: _this.game.fov,
133-
};
134-
new TWEEN.Tween(_this.game.camera)
135-
.to(to, 200)
136-
.easing(TWEEN.Easing.Quadratic.Out)
137-
.onUpdate(function () {
138-
return _this.game.camera.updateProjectionMatrix();
139-
})
140-
.start();
136+
switch (_this.controls[z.code]) {
137+
case "sprint":
138+
var to = {
139+
fov: _this.game.fov,
140+
};
141+
new TWEEN.Tween(_this.game.camera)
142+
.to(to, 200)
143+
.easing(TWEEN.Easing.Quadratic.Out)
144+
.onUpdate(function () {
145+
return _this.game.camera.updateProjectionMatrix();
146+
})
147+
.start();
148+
break;
149+
150+
case "sneak":
151+
_this.game.headHeight = 17;
152+
break;
141153
}
142154
}
143155
});

src/client/scripts/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class Game {
8484
);
8585
this.stats.showPanel(0);
8686
document.body.appendChild(this.stats.dom);
87+
this.headHeight = 17;
8788
this.pii = new PlayerInInventory(this);
8889
this.bb = new BlockBreak(this);
8990
this.bp = new BlockPlace(this);
@@ -170,7 +171,7 @@ class Game {
170171
this.socket.on("move", function (pos) {
171172
var to = {
172173
x: pos.x - 0.5,
173-
y: pos.y + 17,
174+
y: pos.y + _this.headHeight,
174175
z: pos.z - 0.5,
175176
};
176177
new TWEEN.Tween(_this.camera.position)

0 commit comments

Comments
 (0)