added walking acceleration
This commit is contained in:
+15
-2
@@ -2,6 +2,11 @@ import { AnimationMixer, Vector3, Vector2 } from 'three';
|
||||
import { QueryFilterFlags } from '@dimforge/rapier3d';
|
||||
|
||||
const zero2 = new Vector2(0,0);
|
||||
|
||||
const animationBoost = {
|
||||
walk: 1.25
|
||||
}
|
||||
|
||||
class Hero{
|
||||
#walkDirection = new Vector3()
|
||||
#desiredMovement = new Vector2(0,0)
|
||||
@@ -47,6 +52,8 @@ class Hero{
|
||||
|
||||
fadeDuration = 0.2
|
||||
characterGapOffset = 0.01;
|
||||
tsBoost = 1;
|
||||
accelerate = 0;
|
||||
|
||||
lerp = (x, y, a) => x * (1 - a) + y * a;
|
||||
|
||||
@@ -187,7 +194,7 @@ class Hero{
|
||||
} else if (input[0] > 0) {
|
||||
play = 'left'
|
||||
} else if (!this.currentAction.startsWith('idle')){
|
||||
play = 'idle'
|
||||
play = 'idle';
|
||||
} else if (this.actionStart == -1){
|
||||
this.actionStart = 0;
|
||||
play = 'idle';
|
||||
@@ -219,9 +226,15 @@ class Hero{
|
||||
|
||||
this.currentAction = play
|
||||
this.actionStart = 0;
|
||||
this.tsBoost = animationBoost[play] || 1
|
||||
this.accelerate = 0.77;
|
||||
}
|
||||
|
||||
this.animationsMap[this.currentAction].timeScale = this.#timeScale;
|
||||
this.accelerate = this.lerp(this.accelerate, 1, delta);
|
||||
|
||||
velocity *= this.tsBoost * this.accelerate;
|
||||
|
||||
this.animationsMap[this.currentAction].timeScale = this.#timeScale * this.tsBoost * this.accelerate;
|
||||
|
||||
this.actionStart += delta;
|
||||
this.cameraDelta += delta * ( pc.cameraLeft * -1 + pc.cameraRight * 1)
|
||||
|
||||
Reference in New Issue
Block a user