Skip to content

Commit f6877b6

Browse files
committed
fix sneaking playerHeight
1 parent 30abb94 commit f6877b6

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/client/scripts/EventHandler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class EventHandler {
124124

125125
case "sneak":
126126
_this.game.headHeight = 16.7;
127+
_this.game.impulse();
127128
break;
128129
}
129130
}
@@ -149,6 +150,7 @@ class EventHandler {
149150

150151
case "sneak":
151152
_this.game.headHeight = 17;
153+
_this.game.impulse();
152154
break;
153155
}
154156
}

src/client/scripts/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Game {
5151
});
5252
this.renderer.sortObjects = true;
5353
this.scene = new THREE.Scene();
54+
this.playerPos = [0, 0, 0];
5455
this.dimBg = {
5556
"minecraft:overworld": [165 / 255, 192 / 255, 254 / 255],
5657
"minecraft:the_end": [1 / 255, 20 / 255, 51 / 255],
@@ -169,6 +170,7 @@ class Game {
169170
_this.inv_bar.setXp(xp.level, xp.progress);
170171
});
171172
this.socket.on("move", function (pos) {
173+
_this.playerPos = [pos.x - 0.5, pos.y, pos.z - 0.5];
172174
var to = {
173175
x: pos.x - 0.5,
174176
y: pos.y + _this.headHeight,
@@ -179,6 +181,17 @@ class Game {
179181
.easing(TWEEN.Easing.Quadratic.Out)
180182
.start();
181183
});
184+
this.impulse = function () {
185+
var to = {
186+
x: _this.playerPos[0],
187+
y: _this.playerPos[1] + _this.headHeight,
188+
z: _this.playerPos[2],
189+
};
190+
new TWEEN.Tween(_this.camera.position)
191+
.to(to, 100)
192+
.easing(TWEEN.Easing.Quadratic.Out)
193+
.start();
194+
};
182195
this.socket.on("entities", function (entities) {
183196
_this.ent.update(entities);
184197
});

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ io.sockets.on("connection", function (socket) {
164164
} else if (state === "left") {
165165
state = "right";
166166
}
167-
168167
bot.setControlState(state, toggle);
169168
});
170169
socket.on("command", function (com) {

0 commit comments

Comments
 (0)