This commit is contained in:
2026-01-26 16:02:23 -08:00
parent de0052aa0a
commit 0b6f7a55c0

View File

@@ -584,35 +584,15 @@ const Move = (() => {
Position[entity_id] = cornerContactPosition(p.x, p.y, px, py, contact.corner, s.radius);
} else if (contact.edge) {
// if (isLandable(contact.edge) && s.gearDown) s.isLanded = true;
// console.log("CURRENT POSITION", px, py);
// console.log("INTENDED POSITION", p.x, p.y);
// console.log("CONTACT POSITION", contact.position);
const rise = contact.edge.yb-contact.edge.ya;
const run = contact.edge.xb-contact.edge.xa;
const det = v.x * rise - v.y * run;
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");
// bounced velocity vector
// drawLine(p.x, p.y, p.x + contact.velocity.x, p.y + contact.velocity.y, "blue");
const edgeNrmlVect = vector(rise, -run);
const velocityVect = vector(v.x, v.y);
console.log("velocity vector", velocityVect);
console.log("normal vector", edgeNrmlVect);
drawLine(px, py, px + velocityVect.x, py + velocityVect.y, "blue");
const vn = edgeNrmlVect.x * velocityVect.dx + edgeNrmlVect.y * velocityVect.dy;
const vDotn = edgeNrmlVect.x * velocityVect.x + edgeNrmlVect.y * velocityVect.y;
console.log("V dot N", vDotn);
const denom = edgeNrmlVect.x ** 2 + edgeNrmlVect.y ** 2;
console.log("denom", denom);
const vOnNx = vn * velocityVect.dx + velocityVect.x;
const vOnNy = vn * velocityVect.dy + velocityVect.y;
const pVect = {
x: vDotn / denom * edgeNrmlVect.x,
y: vDotn / denom * edgeNrmlVect.y
@@ -622,37 +602,16 @@ const Move = (() => {
// add reverseP and v vectors together
const prVonNx = reverseP.x + v.x;
const prVonNy = reverseP.y + v.y;
// console.log("velocity vector", velocityVect);
// console.log("normal vector", edgeNrmlVect);
// console.log("V dot N", vDotn);
// console.log("prVonNx, prVonNy", prVonNx, prVonNy)
// drawLine(px, py, px + velocityVect.x, py + velocityVect.y, "blue");
// drawLine(px, py, px + edgeNrmlVect.x, py + edgeNrmlVect.y, "black");
// drawLine(contact.position.x, contact.position.y, contact.position.x + prVonNx, contact.position.y + prVonNy, "teal");
console.log("prVonNx, prVonNy", prVonNx, prVonNy)
drawLine(contact.position.x, contact.position.y, contact.position.x + prVonNx, contact.position.y + prVonNy, "teal");
contact.velocity = { x: prVonNx, y: prVonNy };
// contact.velocity = { x: prVonNx, y: prVonNy };
Velocity[entity_id] = { x: prVonNx, y: prVonNy };
// if (det < 0) {
// console.log("moving towards edge");
// console.log("current velocity", vx, vy);
// console.log("current position", px, py);
// console.log("future velocity", v);
// console.log("future position", p);
// console.log("contact position", contact.position);
// drawLine(px, py, p.x, p.y, "green");
// drawCircle(contact.position.x, contact.position.y, "red");
//
//
// // moving towards edge
// // Velocity[entity_id] = contact.velocity;
// Velocity[entity_id] = { x: 0, y: 0 };
// Position[entity_id] = contact.position;
// console.log("position", Position[entity_id], "velocity", Velocity[entity_id]);
// } else {
// console.log("moving away from edge");
//
// // moving away from edge
// Velocity[entity_id] = { x: v.x, y: v.y };
// Position[entity_id] = { x: p.x, y: p.y };
// }
}
} else {
console.log("movi");

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 53 KiB