Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hold shift to run fast #56

Open
wants to merge 1 commit into
base: winter-show-2020
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/js/yorbControls2.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class YorbControls2 {
this.moveLeft = false
this.moveRight = false
this.canJump = false
this.run = false

this.prevTime = performance.now()
this.velocity = new THREE.Vector3()
Expand All @@ -58,6 +59,10 @@ export class YorbControls2 {
'keydown',
(event) => {
switch (event.keyCode) {
case 16: // shift
this.run = true
break

case 38: // up
case 87: // w
this.moveForward = true
Expand All @@ -82,6 +87,7 @@ export class YorbControls2 {
if (this.canJump === true) this.velocity.y = jumpSpeed
this.canJump = false
break

}
},
false
Expand All @@ -91,6 +97,11 @@ export class YorbControls2 {
'keyup',
(event) => {
switch (event.keyCode) {

case 16: // shift
this.run = false
break

case 38: // up
case 87: // w
this.moveForward = false
Expand Down Expand Up @@ -174,7 +185,13 @@ export class YorbControls2 {
// update for these controls, which are unfortunately not included in the controls directly...
// see: https://github.com/mrdoob/three.js/issues/5566
updateControls() {
let speed = 50
let speed

if (this.run) { // if we hold shift, we 'run'
speed = 200
} else {
speed = 50
}

var time = performance.now()
var rawDelta = (time - this.prevTime) / 1000
Expand Down