WIP: edge collision position

This commit is contained in:
2026-01-04 23:15:48 -08:00
parent 2f2a82c46f
commit df2eb64ed5

View File

@@ -204,15 +204,16 @@
let acceleration; // meters per second per second let acceleration; // meters per second per second
let rotate = 0; let rotate = 0;
let mult = 1000; let mult = 10000;
const s = { const s = {
position: { x: 0, y: 0 }, position: { x: 0, y: 0 },
// velocity: { x: 0, y: 0 }, // velocity: { x: 0, y: 0 },
// velocity: { x: 5, y: 10 }, velocity: { x: 5, y: 7 },
velocity: { x: 5*mult, y: 10*mult }, // velocity: { x: 5*mult, y: 8*mult },
acceleration: { x: 0, y: 0 }, acceleration: { x: 5, y: 7 },
// acceleration: { x: 0, y: 0 },
rotate: 0, rotate: 0,
collision: null, collision: null,
isLanded: false, isLanded: false,
@@ -495,7 +496,7 @@
} }
const { a, b } = perppts; const { a, b } = perppts;
if (a && b) drawLine(a.x, a.y, b.x, b.y); // if (a && b) drawLine(a.x, a.y, b.x, b.y);
return walls.reduce((acc, w) => { return walls.reduce((acc, w) => {
const filtered = a && b ? w.corners.filter(c => { const filtered = a && b ? w.corners.filter(c => {
@@ -898,10 +899,10 @@
const changeY = 0.001 * elapsed * velocityY; const changeY = 0.001 * elapsed * velocityY;
let { x, y } = s.position; let { x, y } = s.position;
console.log("current position", x, y); // console.log("current position", x, y);
let position = [positionX, positionY] = [changeX + x, changeY + y]; let position = [positionX, positionY] = [changeX + x, changeY + y];
let [xc, yc] = position; let [xc, yc] = position;
console.log("future position", xc, yc); // console.log("future position", xc, yc);
const collE = getCollisionEdges(edgeszz, position); const collE = getCollisionEdges(edgeszz, position);
@@ -910,16 +911,16 @@
const det = (xb - xa) * (y - ya) - (x - xa) * (yb - ya); const det = (xb - xa) * (y - ya) - (x - xa) * (yb - ya);
return det < 0; return det < 0;
}); });
console.log("edges facing ship", efs); // console.log("edges facing ship", efs);
const positionSeg = { xa: x, ya: y, xb: xc, yb: yc };
// console.log("positionSeg", positionSeg);
const edgeCollision = efs.find(({ edge, wall }) => { const edgeCollision = efs.find(({ edge, wall }) => {
const { xa, ya, xb, yb } = edge; const { xa, ya, xb, yb } = edge;
if (xc === x && yc === y) return; if (xc === x && yc === y) return;
const positionSeg = { xa: x, ya: y, xb: xc, yb: yc };
// const slopeps = slope(positionSeg);
// const posNormIntxn = perpIntxn(slopeps, x, y, c.corner.x, c.corner.y);
const rise = yb - ya; const rise = yb - ya;
const run = xb - xa; const run = xb - xa;
const length = distance(xa, ya, xb, yb); const length = distance(xa, ya, xb, yb);
@@ -939,10 +940,15 @@
const roundedT = +t.toFixed(2); const roundedT = +t.toFixed(2);
const roundedS = +s.toFixed(2); const roundedS = +s.toFixed(2);
console.log("positionSeg", positionSeg, "edgeSeg", edgeSeg); console.log("positionSeg", positionSeg);
console.log("edgeSeg", edgeSeg);
console.log("s", roundedS, "t", roundedT); console.log("s", roundedS, "t", roundedT);
return roundedS <= 1 && roundedT >= 0; // return roundedS >= 0 && roundedS <= 1 && roundedT >= 0 && roundedT <= 1;
return roundedS <= 1 && roundedT >= 0 && roundedT <= 1;
// return roundedS >= 0 && roundedS <= 1 && roundedT <= 1;
// return roundedS >= 0 && roundedS <= 1 && roundedT <= 1;
// return false;
}); });
efs.forEach(({ edge, wall }) => { efs.forEach(({ edge, wall }) => {
@@ -996,7 +1002,8 @@
// return +hc.toFixed(2) <= shipRadius; // return +hc.toFixed(2) <= shipRadius;
// }); // });
s.collision = cornerColl || edgeCollision; // s.collision = cornerColl || edgeCollision;
s.collision = edgeCollision || cornerColl;
if (s.collision) console.log("COLLISION", s.collision); if (s.collision) console.log("COLLISION", s.collision);

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 45 KiB