camera idle behavior
This commit is contained in:
@@ -45,6 +45,8 @@ export class CharacterControls {
|
||||
this.direction = this.model.rotation.y;
|
||||
this.directionVelocity = 0;
|
||||
this.actionStart = 0;
|
||||
this.cameraDelta = 0;
|
||||
this.cameraIdleDelta = 0;
|
||||
//this.toggleRun = true
|
||||
}
|
||||
|
||||
@@ -53,7 +55,7 @@ export class CharacterControls {
|
||||
}
|
||||
|
||||
update(world, delta, pointerControls) {
|
||||
const directionPressed = pointerControls.moving()
|
||||
const directionPressed = pointerControls.moving
|
||||
let input = this.getInput(pointerControls)
|
||||
|
||||
let play = this.currentAction || 'idle', velocity = this.walkVelocity;
|
||||
@@ -84,12 +86,18 @@ export class CharacterControls {
|
||||
this.fadeDuration = 1;
|
||||
}
|
||||
|
||||
if (this.currentAction.startsWith('idle') && play != 'idle'){
|
||||
this.cameraIdleDelta += delta * 0.33;
|
||||
}else {
|
||||
this.cameraIdleDelta = 0;
|
||||
}
|
||||
|
||||
if (this.currentAction != play) {
|
||||
const toPlay = this.animationsMap[play]
|
||||
const current = this.animationsMap[this.currentAction]
|
||||
|
||||
current.fadeOut(this.fadeDuration)
|
||||
toPlay.timeScale = 0.77;
|
||||
toPlay.timeScale = 0.5;
|
||||
toPlay.reset().fadeIn(this.fadeDuration).play();
|
||||
|
||||
this.currentAction = play
|
||||
@@ -99,6 +107,8 @@ export class CharacterControls {
|
||||
this.mixer.update(delta)
|
||||
this.actionStart += delta;
|
||||
|
||||
this.cameraDelta += delta * ( pointerControls.cameraLeft * -1 + pointerControls.cameraRight * 1)
|
||||
|
||||
this.walkDirection.x = this.walkDirection.y = this.walkDirection.z = 0
|
||||
|
||||
if (directionPressed) {
|
||||
@@ -142,9 +152,9 @@ export class CharacterControls {
|
||||
|
||||
let cameraPosition = new THREE.Vector3().copy(this.camera.position)
|
||||
let cameraDesiredPosition = new THREE.Vector3(
|
||||
this.model.position.x + 5* Math.sin(this.model.rotation.y + Math.PI),
|
||||
this.model.position.x + 5* Math.sin(this.model.rotation.y + Math.PI + this.cameraDelta + this.cameraIdleDelta),
|
||||
3,
|
||||
this.model.position.z + 5* Math.cos(this.model.rotation.y + Math.PI)
|
||||
this.model.position.z + 5* Math.cos(this.model.rotation.y + Math.PI + this.cameraDelta + this.cameraIdleDelta)
|
||||
)
|
||||
|
||||
cameraPosition.lerp(cameraDesiredPosition, delta*2)
|
||||
|
||||
Reference in New Issue
Block a user