advanced character animations
This commit is contained in:
@@ -44,6 +44,7 @@ export class CharacterControls {
|
|||||||
|
|
||||||
this.direction = this.model.rotation.y;
|
this.direction = this.model.rotation.y;
|
||||||
this.directionVelocity = 0;
|
this.directionVelocity = 0;
|
||||||
|
//this.toggleRun = true
|
||||||
}
|
}
|
||||||
|
|
||||||
switchRunToggle() {
|
switchRunToggle() {
|
||||||
@@ -52,12 +53,17 @@ export class CharacterControls {
|
|||||||
|
|
||||||
update(world, delta, pointerControls) {
|
update(world, delta, pointerControls) {
|
||||||
const directionPressed = pointerControls.moving()
|
const directionPressed = pointerControls.moving()
|
||||||
|
let input = this.getInput(pointerControls)
|
||||||
|
|
||||||
var play = '';
|
var play = '';
|
||||||
if (directionPressed && this.toggleRun) {
|
if (input[1] && this.toggleRun) {
|
||||||
play = 'run'
|
play = 'run'
|
||||||
} else if (directionPressed) {
|
} else if (input[1]) {
|
||||||
play = 'walk'
|
play = 'walk'
|
||||||
|
} else if (input[0] < 0) {
|
||||||
|
play = 'right'
|
||||||
|
} else if (input[0] > 0) {
|
||||||
|
play = 'left'
|
||||||
}else {
|
}else {
|
||||||
play = 'idle'
|
play = 'idle'
|
||||||
}
|
}
|
||||||
@@ -72,17 +78,16 @@ export class CharacterControls {
|
|||||||
this.currentAction = play
|
this.currentAction = play
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mixer.update(delta)
|
this.mixer.update(delta*0.5)
|
||||||
|
|
||||||
this.walkDirection.x = this.walkDirection.y = this.walkDirection.z = 0
|
this.walkDirection.x = this.walkDirection.y = this.walkDirection.z = 0
|
||||||
|
|
||||||
let velocity = 0
|
let velocity = 0
|
||||||
if (this.currentAction == 'run' || this.currentAction == 'walk') {
|
if (directionPressed) {
|
||||||
let input = this.getInput(pointerControls)
|
|
||||||
this.directionVelocity = this.directionVelocity * 2.5 * Math.abs(input[0])
|
this.directionVelocity = this.directionVelocity * 2.5 * Math.abs(input[0])
|
||||||
this.direction += input[0] * delta * 2.5 //this.directionVelocity;
|
this.direction += input[0] * delta * 2.5 //this.directionVelocity;
|
||||||
this.model.rotation.y = this.direction;
|
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.applyAxisAngle(this.rotateAngle, this.direction)
|
||||||
this.walkDirection.normalize();
|
this.walkDirection.normalize();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user