summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script.js14
1 files changed, 13 insertions, 1 deletions
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)