From 5c6a84b1f264d5abbc3a776b1723271bad0d6c7b Mon Sep 17 00:00:00 2001 From: goynov Date: Tue, 14 Apr 2026 12:04:34 +0300 Subject: [PATCH] added walking acceleration --- src/lib/Hero.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/Hero.js b/src/lib/Hero.js index 5568751..aedd39b 100644 --- a/src/lib/Hero.js +++ b/src/lib/Hero.js @@ -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)