Fix inv sqrt NaN issue

This commit is contained in:
Schluffe
2026-03-21 12:37:09 +01:00
parent fb5928dca7
commit bb4a9f505b
2 changed files with 32 additions and 33 deletions
+12 -5
View File
@@ -13,7 +13,12 @@ import {
moveAndCollide,
Shape,
} from "#/engine/system/physics.ts";
import { createVector, type Vector } from "#/engine/Vector.ts";
import {
createVector,
normalize,
scale,
type Vector,
} from "#/engine/Vector.ts";
import charIdle from "#/game/assets/char-idle.png";
const speed = 0.05;
@@ -36,10 +41,12 @@ process((id, delta) => {
position.y = pointer.position.y;
}
velocity.x -= keyboardInput.arrowLeft ? speed : 0;
velocity.x += keyboardInput.arrowRight ? speed : 0;
velocity.y -= keyboardInput.arrowUp ? speed : 0;
velocity.y += keyboardInput.arrowDown ? speed : 0;
velocity.x -= keyboardInput.arrowLeft ? 1 : 0;
velocity.x += keyboardInput.arrowRight ? 1 : 0;
velocity.y -= keyboardInput.arrowUp ? 1 : 0;
velocity.y += keyboardInput.arrowDown ? 1 : 0;
normalize(velocity);
scale(velocity, speed);
position.x = Math.round(velocity.x * delta + position.x);
position.y = Math.round(velocity.y * delta + position.y);