From 6609d2a510f2712da91f4f0f877745f04519453d Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 30 Jan 2024 03:14:33 +0000 Subject: Disable boop logging, attempt to fix glitching into walls --- script.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 3909b89..7fdc149 100644 --- a/script.js +++ b/script.js @@ -108,7 +108,7 @@ function collide(a, b, c, n) { b.vx += n.x * j / b.m b.vy += n.y * j / b.m b.w += -cr(cb, n) * j / b.mi - console.log('boop') + // console.log('boop') } // Collision of object a with wall at position k and direction d @@ -182,6 +182,18 @@ function tick() { a.x += a.vx a.y += a.vy a.th += a.w + // Don't allow glitching into walls + /* const px = a.p.map(x => rot(a, x).x) + let k = Math.min(...px) - rad + if (k < 0) a.x -= k + k = window.innerWidth - Math.max(...px) - rad + if (k < 0) a.x += k + const py = a.p.map(x => rot(a, x).y) + k = Math.min(...py) - rad + if (k < 0) a.y -= k + k = window.innerHeight - Math.max(...py) - rad + if (k < 0) a.y += k */ + // Friction if (Math.abs(a.vx) > 0.001) a.vx -= 0.001 * Math.sign(a.vx) if (Math.abs(a.vy) > 0.001) a.vy -= 0.001 * Math.sign(a.vy) if (Math.abs(a.w) > 0.00001) a.w -= 0.00001 * Math.sign(a.w) -- cgit v1.2.3-70-g09d2