From 5bb861c376ef7dfddf5eb4080ba44aa657547f54 Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Sat, 24 Jan 2026 13:19:43 -0800 Subject: [PATCH] WIP: Bouncing working but still not perfect --- html/images/space.svg | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/html/images/space.svg b/html/images/space.svg index 5ddd650..7e75280 100644 --- a/html/images/space.svg +++ b/html/images/space.svg @@ -556,22 +556,22 @@ const Move = (() => { if (contact.corner) { contact.position = cornerContactPosition(p.x, p.y, px, py, contact.corner, s.radius); - console.log("contact position", contact.position); - drawLine(contact.position.x, contact.position.y, contact.position.x + vx, contact.position.y + vy, "blue"); + // console.log("contact position", contact.position); + // drawLine(contact.position.x, contact.position.y, contact.position.x + vx, contact.position.y + vy, "blue"); const contactV = { x: contact.position.y - contact.corner.y, y: contact.position.x - contact.corner.x }; - console.log("contactV", contactV); + // console.log("contactV", contactV); const normalVect = { x: contact.position.x - contact.corner.x, y: contact.position.y - contact.corner.y }; - console.log("normal vector", normalVect); - drawLine(contact.corner.x, contact.corner.y, contact.corner.x + normalVect.x, contact.corner.y + normalVect.y, "black"); + // console.log("normal vector", normalVect); + // drawLine(contact.corner.x, contact.corner.y, contact.corner.x + normalVect.x, contact.corner.y + normalVect.y, "black"); const tangentVect = { x: normalVect.y, y: -normalVect.x }; - drawLine(contact.position.x, contact.position.y, contact.position.x + tangentVect.x, contact.position.y + tangentVect.y, "green"); + // drawLine(contact.position.x, contact.position.y, contact.position.x + tangentVect.x, contact.position.y + tangentVect.y, "green"); contact.velocity = bounceVector(v, tangentVect.x, tangentVect.y); - console.log("tangent vector", tangentVect); + // console.log("tangent vector", tangentVect); - drawLine(contact.position.x, contact.position.y, contact.position.x + contact.velocity.x, contact.position.y + contact.velocity.y, "blue"); + // drawLine(contact.position.x, contact.position.y, contact.position.x + contact.velocity.x, contact.position.y + contact.velocity.y, "blue"); // Velocity[entity_id] = { x: 0, y: 0 }; Velocity[entity_id] = contact.velocity; @@ -585,23 +585,26 @@ const Move = (() => { const rise = contact.edge.yb-contact.edge.ya; const run = contact.edge.xb-contact.edge.xa; - drawLine(p.x - v.x, p.y - v.y, p.x, p.y, "blue"); // velocity vector + // drawLine(p.x - v.x, p.y - v.y, p.x, p.y, "blue"); // velocity vector const det = v.x * rise - v.y * run; - drawLine(contact.edge.xa, contact.edge.ya, contact.edge.xb, contact.edge.yb, "green"); // edge vector + // drawLine(contact.edge.xa, contact.edge.ya, contact.edge.xb, contact.edge.yb, "green"); // edge vector // contact.velocity = { x: prAvx - prBvx, y: prAvy - prBvy }; contact.velocity = bounceVector(v, run, rise); // edge normal vector - drawLine(p.x, p.y, p.x + contact.velocity.vec2.rightNormal.x , p.y + contact.velocity.vec2.rightNormal.y, "black"); + // drawLine(p.x, p.y, p.x + contact.velocity.vec2.rightNormal.x , p.y + contact.velocity.vec2.rightNormal.y, "black"); // bounced velocity vector - drawLine(p.x, p.y, p.x + contact.velocity.x, p.y + contact.velocity.y, "blue"); + // drawLine(p.x, p.y, p.x + contact.velocity.x, p.y + contact.velocity.y, "blue"); if (det < 0) { + // moving towards edge Velocity[entity_id] = contact.velocity; + // Velocity[entity_id] = { x: 0, y: 0 }; Position[entity_id] = contact.position; } else { + // moving away from edge Velocity[entity_id] = { x: v.x, y: v.y }; Position[entity_id] = { x: p.x, y: p.y }; } @@ -694,10 +697,10 @@ function init() { started = false; const mult = 10; - s.position = { x: 0, y: -10 }; + s.position = { x: 0, y: -8 }; // s.velocity = { x: 0, y: -10 }; // s.velocity = { x: 10, y: 20 }; - s.velocity = { x: 5, y: 0 }; + s.velocity = { x: 10, y: 20 }; s.angularVelocity = 0; // s. velocity = { x: -5*mult, y: 7*mult }; @@ -1264,7 +1267,7 @@ function updateShip(s, elapsed) { current = s.collision; s.collision = detectCollision([px, py], p, s.velocity, s.radius, map, s.gearDown); - if (!current && s.collision) console.log("COLLISION", s.collision); + // if (!current && s.collision) console.log("COLLISION", s.collision); legs.style.display = s.gearDown ? "initial" : "none";