diff --git a/src/lib/CharacterControls.js b/src/lib/CharacterControls.js index ca04911..dfcb18b 100644 --- a/src/lib/CharacterControls.js +++ b/src/lib/CharacterControls.js @@ -44,6 +44,7 @@ export class CharacterControls { this.direction = this.model.rotation.y; this.directionVelocity = 0; + //this.toggleRun = true } switchRunToggle() { @@ -52,13 +53,18 @@ export class CharacterControls { update(world, delta, pointerControls) { const directionPressed = pointerControls.moving() + let input = this.getInput(pointerControls) var play = ''; - if (directionPressed && this.toggleRun) { + if (input[1] && this.toggleRun) { play = 'run' - } else if (directionPressed) { + } else if (input[1]) { play = 'walk' - } else { + } else if (input[0] < 0) { + play = 'right' + } else if (input[0] > 0) { + play = 'left' + }else { play = 'idle' } @@ -72,17 +78,16 @@ export class CharacterControls { this.currentAction = play } - this.mixer.update(delta) + this.mixer.update(delta*0.5) this.walkDirection.x = this.walkDirection.y = this.walkDirection.z = 0 let velocity = 0 - if (this.currentAction == 'run' || this.currentAction == 'walk') { - let input = this.getInput(pointerControls) + if (directionPressed) { this.directionVelocity = this.directionVelocity * 2.5 * Math.abs(input[0]) this.direction += input[0] * delta * 2.5 //this.directionVelocity; this.model.rotation.y = this.direction; - this.walkDirection.set(input[0]*0.33, 0, input[1]) + this.walkDirection.set(0, 0, input[1]) this.walkDirection.applyAxisAngle(this.rotateAngle, this.direction) this.walkDirection.normalize();