Skip to content

Instantly share code, notes, and snippets.

@darkwave
Created May 7, 2020 16:13
Show Gist options
  • Save darkwave/3d061a5d8d5a44bd9e3fe303920d9f48 to your computer and use it in GitHub Desktop.
Save darkwave/3d061a5d8d5a44bd9e3fe303920d9f48 to your computer and use it in GitHub Desktop.
function init() {
player.setCamera(this);
var playerObject = scene.getObjectByName( "Player", true );
if (playerObject)
this.lookAt(playerObject.position);
}
function update(event) {
if (moveUp) {
this.rotation.x -= 0.01;
}
}
function init() {
console.log('INIT');
window.moveForward = false;
window.moveBackward = false;
window.moveLeft = false;
window.moveRight = false;
window.moveUp = false;
var onKeyDown = function ( event ) {
switch ( event.keyCode ) {
case 38: // up
moveUp = true;
break;
case 87: // w
moveForward = true;
break;
case 37: // left
case 65: // a
moveLeft = true;
break;
case 40: // down
case 83: // s
moveBackward = true;
break;
case 39: // right
case 68: // d
moveRight = true;
break;
}
};
var onKeyUp = function ( event ) {
switch ( event.keyCode ) {
case 38: // up
moveUp = false;
break;
case 87: // w
moveForward = false;
break;
case 37: // left
case 65: // a
moveLeft = false;
break;
case 40: // down
case 83: // s
moveBackward = false;
break;
case 39: // right
case 68: // d
moveRight = false;
break;
}
};
document.addEventListener( 'keydown', onKeyDown, false );
document.addEventListener( 'keyup', onKeyUp, false );
}
function update( event ) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment