diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-17 01:26:50 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-17 01:26:50 +0200 |
commit | b65849bce3fe8ff8d6baebf29728868d4f164827 (patch) | |
tree | 4d0a9b235ba76f4f451a422e64fcfec045d18eea /test-client/util.ts | |
parent | fe164b52e7dd3468e53c8d5d4883b432cce18fbf (diff) | |
download | hurrycurry-b65849bce3fe8ff8d6baebf29728868d4f164827.tar hurrycurry-b65849bce3fe8ff8d6baebf29728868d4f164827.tar.bz2 hurrycurry-b65849bce3fe8ff8d6baebf29728868d4f164827.tar.zst |
player moves with camera on grid
Diffstat (limited to 'test-client/util.ts')
-rw-r--r-- | test-client/util.ts | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test-client/util.ts b/test-client/util.ts index 994e6acf..99f0c013 100644 --- a/test-client/util.ts +++ b/test-client/util.ts @@ -2,3 +2,9 @@ export interface V2 { x: number, y: number } export function length(p: V2): number { return Math.sqrt(p.x * p.x + p.y * p.y) } export function normalize_mut(p: V2) { const l = length(p); if (l == 0) return; p.x /= l; p.y /= l } export function normalize(p: V2): V2 { let l = length(p); if (l == 0) l = 1; return { x: p.x / l, y: p.y / l } } +export function lerp_v2_mut(current: V2, target: V2, dt: number) { + current.x = target.x + (current.x - target.x) * Math.exp(-dt) + current.y = target.y + (current.y - target.y) * Math.exp(-dt) +} +export function floor_v2(p: V2): V2 { return { x: Math.floor(p.x), y: Math.floor(p.y) } } +export function ceil_v2(p: V2): V2 { return { x: Math.ceil(p.x), y: Math.ceil(p.y) } } |