WIP: place ship in final collision position
This commit is contained in:
@@ -659,11 +659,35 @@
|
|||||||
// console.log("ship landed", s, "edge", s.collision.edge.ya);
|
// console.log("ship landed", s, "edge", s.collision.edge.ya);
|
||||||
if (s.collision) {
|
if (s.collision) {
|
||||||
// console.log("a");
|
// console.log("a");
|
||||||
s.velocity = { x: 0, y: 0 };
|
|
||||||
const baseSlope = slope(s.collision.edge);
|
const baseSlope = slope(s.collision.edge);
|
||||||
|
const { xa, ya, xb, yb } = s.collision.edge;
|
||||||
|
const baseLine = { x1: xa, y1: ya, x2: xb, y2: yb };
|
||||||
|
|
||||||
|
const velocityLine = {
|
||||||
|
x1: s.position.x,
|
||||||
|
y1: s.position.y,
|
||||||
|
x2: s.position.x + s.velocity.x,
|
||||||
|
y2: s.position.y + s.velocity.y
|
||||||
|
};
|
||||||
|
|
||||||
|
const baseNrmlIntxn = perpIntxn(baseSlope, xa, ya, s.position.x, s.position.y);
|
||||||
|
const baseVelIntxn = lineIntxnPt(baseLine, velocityLine);
|
||||||
|
const baseSegLength = distance(baseNrmlIntxn.x, baseNrmlIntxn.y , baseVelIntxn.x, baseVelIntxn.y);
|
||||||
|
const normalSegLength = distance(baseNrmlIntxn.x, baseNrmlIntxn.y, s.position.x, s.position.y);
|
||||||
|
const theta = Math.atan(normalSegLength / baseSegLength);
|
||||||
|
const h = 5 / Math.sin(theta);
|
||||||
|
const cl = document.createElementNS(namespaceURIsvg, 'line');
|
||||||
|
cl.setAttribute('x1', baseVelIntxn.x);
|
||||||
|
cl.setAttribute('y1', baseVelIntxn.y);
|
||||||
|
cl.setAttribute('x2', s.position.x);
|
||||||
|
cl.setAttribute('y2', s.position.y);
|
||||||
|
console.log("h", h);
|
||||||
|
|
||||||
|
const clPt = cl.getPointAtLength(h);
|
||||||
|
console.log("clPt", clPt);
|
||||||
|
|
||||||
const normalSlope = 1 / -baseSlope;
|
const normalSlope = 1 / -baseSlope;
|
||||||
const radAngle = Math.atan(normalSlope);
|
const radAngle = Math.atan(normalSlope);
|
||||||
const { xa, ya, xb, yb } = s.collision.edge;
|
|
||||||
const foot = perpIntxn(baseSlope, xa, ya, xc, yc);
|
const foot = perpIntxn(baseSlope, xa, ya, xc, yc);
|
||||||
const el = document.createElementNS(namespaceURIsvg, 'line');
|
const el = document.createElementNS(namespaceURIsvg, 'line');
|
||||||
el.setAttribute('x1', foot.x);
|
el.setAttribute('x1', foot.x);
|
||||||
@@ -683,7 +707,7 @@
|
|||||||
// console.log("foot", foot, "line", el, "length", el.getTotalLength());
|
// console.log("foot", foot, "line", el, "length", el.getTotalLength());
|
||||||
svg.appendChild(el);
|
svg.appendChild(el);
|
||||||
// console.log(el, el.getTotalLength());
|
// console.log(el, el.getTotalLength());
|
||||||
const collPt = el.getPointAtLength(5);
|
// const collPt = el.getPointAtLength(5);
|
||||||
// let l = drawLine(foot.x, foot.y, foot.x - posX, foot.y - posY);
|
// let l = drawLine(foot.x, foot.y, foot.x - posX, foot.y - posY);
|
||||||
// let l = drawLine(foot.x, foot.y, foot.x - posY, foot.y - posX);
|
// let l = drawLine(foot.x, foot.y, foot.x - posY, foot.y - posX);
|
||||||
// s.position = { x: foot.x - posY, y: foot.y - posX };
|
// s.position = { x: foot.x - posY, y: foot.y - posX };
|
||||||
@@ -691,7 +715,10 @@
|
|||||||
// console.log("ship position", s.position);
|
// console.log("ship position", s.position);
|
||||||
// console.log("line length", l.getTotalLength(), l, foot.x - posY, foot.y - posX);
|
// console.log("line length", l.getTotalLength(), l, foot.x - posY, foot.y - posX);
|
||||||
|
|
||||||
s.position = { x: xc, y: yc }
|
s.velocity = { x: 0, y: 0 };
|
||||||
|
// s.position = { x: xc, y: yc }
|
||||||
|
s.position = { x: clPt.x, y: clPt.y }
|
||||||
|
console.log("s.position", s.position);
|
||||||
s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
|
s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
|
||||||
} else {
|
} else {
|
||||||
// console.log("c");
|
// console.log("c");
|
||||||
@@ -860,7 +887,7 @@
|
|||||||
// console.log("S POSITION", s.position);
|
// console.log("S POSITION", s.position);
|
||||||
updateBullets(elapsed);
|
updateBullets(elapsed);
|
||||||
// updateEdges(position);
|
// updateEdges(position);
|
||||||
updateLines(elapsed, collE, {x, y}, {x: s.position.x, y: s.position.y});
|
if (!s.collision) updateLines(elapsed, collE, {x, y}, s.position);
|
||||||
if (drawCollisionLines) updateTriangles(position);
|
if (drawCollisionLines) updateTriangles(position);
|
||||||
|
|
||||||
// const collision = detectCollisions(position, allWallCorners, findAllEdges(allEdgePts, position), getCollisionEdges(edgeszz, position));
|
// const collision = detectCollisions(position, allWallCorners, findAllEdges(allEdgePts, position), getCollisionEdges(edgeszz, position));
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 36 KiB |
Reference in New Issue
Block a user