Skip to content

Commit

Permalink
fixed keybind issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ItziSpyder committed Jul 19, 2024
1 parent ea63f2f commit 66118ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
17 changes: 2 additions & 15 deletions canvasV2/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,26 @@ function updateRotation() {
function updatePosition() {
var yaw = prevRotation[1]
var dir = new Vector(0, 0, 0)
var horizontal = false

if (keyLeft) {
dir = dir.add(1, 0, 0)
horizontal = true
}
if (keyRight) {
dir = dir.add(-1, 0, 0)
horizontal = true
}
if (keyForward) {
dir = dir.add(0, 0, -1)
horizontal = true
}
if (keyBackward) {
dir = dir.add(0, 0, 1)
horizontal = true
}

var standingOn = camera.add(0, -height - 0.001, 0).round()

if (keyJump) {
dir = dir.add(0, 1, 0)
}
if (keyDescent) {
dir = dir.add(0, -1, 0)
}
// else if (world.getVoxel(standingOn.x, standingOn.y, standingOn.z) == null) {
// dir = dir.add(0, -1, 0)
// }

var quatYaw = new Quaternion(1, 0, 0, 0).rotationY(math.toRadians(-yaw))
dir = quatYaw.transform(dir.mul(0.15, 0.15, 0.15))
Expand Down Expand Up @@ -143,7 +133,7 @@ document.body.addEventListener('contextmenu', e => {
document.body.addEventListener('mousemove', updateMouse)
document.body.addEventListener('keypress', e => {
// console.log(e)
switch (e.key) {
switch (e.key.toLowerCase()) {
case 'w':
keyForward = true
break
Expand All @@ -160,14 +150,11 @@ document.body.addEventListener('keypress', e => {
keyJump = !e.shiftKey
keyDescent = e.shiftKey
break
case 'q':
cursorLock = !cursorLock
break
}
})
document.body.addEventListener('keyup', e => {
// console.log('release: ' + e.key)
switch (e.key) {
switch (e.key.toLowerCase()) {
case 'w':
keyForward = false
break
Expand Down
10 changes: 5 additions & 5 deletions canvasV2/js/objects/voxel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class Voxel {
this.consumerVertices(world, vertexConsumer, this.color)
vertexConsumer.draw(rotation, focalPoint, camera)

if (this.outline) {
vertexConsumer.begin(Buffer.MODE_QUAD_LINES, 5)
this.consumerVertices(world, vertexConsumer, 'red')
vertexConsumer.draw(rotation, focalPoint, camera)
}
// if (this.outline) {
// vertexConsumer.begin(Buffer.MODE_QUAD_LINES, 5)
// this.consumerVertices(world, vertexConsumer, 'red')
// vertexConsumer.draw(rotation, focalPoint, camera)
// }
}

consumerVertices(world, vertexConsumer, color) {
Expand Down

0 comments on commit 66118ee

Please sign in to comment.