From b509ba12ea6c30b1e0121e725e67b07ec740fb0f Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Thu, 22 Jan 2026 12:30:23 -0800 Subject: [PATCH] WIP: bounce off walls --- html/images/space.svg | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/html/images/space.svg b/html/images/space.svg index 124a817..e9e9bf4 100644 --- a/html/images/space.svg +++ b/html/images/space.svg @@ -126,7 +126,6 @@ - @@ -572,18 +571,21 @@ const Move = (() => { console.log("theta between edge vector and velocity vector", edgeTheta, "degrees", edgeTheta * 180 / Math.PI); console.log("theta between normal vector and velocity vector", normalTheta, "degrees", normalTheta * 180 / Math.PI); + const newTheta = (Math.PI - normalTheta) * 2; + const newY = -Math.cos(newTheta) * velocityVectorMagnitude; + const newX = Math.sin(newTheta) * velocityVectorMagnitude; Velocity[entity_id] = { // x: v.x * Math.sin(thetaX) + v.y * Math.cos(thetaY), // y: v.y * Math.sin(thetaY) + v.x * Math.cos(thetaX) - x: v.y, + x: newX, // y: v.y * Math.sin(thetaY) + v.x * Math.cos(thetaX) - y: 0 + y: newY }; console.log("VELOCITY AFTER", Velocity[entity_id]); - Position[entity_id] = { x: p.x, y: p.y }; + // Position[entity_id] = { x: p.x, y: p.y }; // console.log("contact", contact.edge); // Position[entity_id] = contact.position; } else {