idle mode
This commit is contained in:
@@ -44,6 +44,7 @@ export class CharacterControls {
|
||||
|
||||
this.direction = this.model.rotation.y;
|
||||
this.directionVelocity = 0;
|
||||
this.actionStart = 0;
|
||||
//this.toggleRun = true
|
||||
}
|
||||
|
||||
@@ -55,34 +56,51 @@ export class CharacterControls {
|
||||
const directionPressed = pointerControls.moving()
|
||||
let input = this.getInput(pointerControls)
|
||||
|
||||
var play = '';
|
||||
let play = this.currentAction || 'idle', velocity = this.walkVelocity;
|
||||
this.fadeDuration = 0.2;
|
||||
if (input[1] && this.toggleRun) {
|
||||
play = 'run'
|
||||
} else if (input[1]) {
|
||||
play = 'run';
|
||||
velocity = this.runVelocity
|
||||
} else if (input[1] > 0) {
|
||||
play = 'walk'
|
||||
} else if (input[1] < 0) {
|
||||
play = 'backward'
|
||||
velocity = this.walkVelocity / 3
|
||||
} else if (input[0] < 0) {
|
||||
play = 'right'
|
||||
} else if (input[0] > 0) {
|
||||
play = 'left'
|
||||
}else {
|
||||
} else if (!this.currentAction.startsWith('idle')){
|
||||
play = 'idle'
|
||||
}
|
||||
|
||||
if (this.currentAction.startsWith('idle') && play.startsWith('idle') && this.actionStart > 10){
|
||||
let idx = 1 + parseInt(this.currentAction.split('.')[1] || 0);
|
||||
if (this.animationsMap[`idle.${idx}`]) {
|
||||
play = `idle.${idx}`
|
||||
}else{
|
||||
play = 'idle'
|
||||
}
|
||||
this.fadeDuration = 1;
|
||||
}
|
||||
|
||||
if (this.currentAction != play) {
|
||||
const toPlay = this.animationsMap[play]
|
||||
const current = this.animationsMap[this.currentAction]
|
||||
|
||||
current.fadeOut(this.fadeDuration)
|
||||
toPlay.timeScale = 0.77;
|
||||
toPlay.reset().fadeIn(this.fadeDuration).play();
|
||||
|
||||
this.currentAction = play
|
||||
this.actionStart = 0;
|
||||
}
|
||||
|
||||
this.mixer.update(delta*0.5)
|
||||
this.mixer.update(delta)
|
||||
this.actionStart += delta;
|
||||
|
||||
this.walkDirection.x = this.walkDirection.y = this.walkDirection.z = 0
|
||||
|
||||
let velocity = 0
|
||||
if (directionPressed) {
|
||||
this.directionVelocity = this.directionVelocity * 2.5 * Math.abs(input[0])
|
||||
this.direction += input[0] * delta * 2.5 //this.directionVelocity;
|
||||
@@ -100,7 +118,6 @@ export class CharacterControls {
|
||||
//this.camera.updateProjectionMatrix();
|
||||
|
||||
// run/walk velocity
|
||||
velocity = this.currentAction == 'run' ? this.runVelocity : this.walkVelocity
|
||||
}
|
||||
|
||||
this.walkDirection.x = this.walkDirection.x * velocity * delta// + this.model.position.x
|
||||
|
||||
Reference in New Issue
Block a user