WIP: slide along edge but still fall through sometimes
This commit is contained in:
@@ -584,24 +584,31 @@ 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;
|
||||
const accVect = vector(ax, ay);
|
||||
const rise = contact.edge.yb-contact.edge.ya;
|
||||
const run = contact.edge.xb-contact.edge.xa;
|
||||
const edgeNrmlVect = vector(rise, -run);
|
||||
const velocityVect = vector(v.x, v.y);
|
||||
|
||||
|
||||
const vn = edgeNrmlVect.x * velocityVect.dx + edgeNrmlVect.y * velocityVect.dy;
|
||||
const vDotn = edgeNrmlVect.x * velocityVect.x + edgeNrmlVect.y * velocityVect.y;
|
||||
const aDotn = edgeNrmlVect.x * accVect.x + edgeNrmlVect.y * accVect.y;
|
||||
const denom = edgeNrmlVect.x ** 2 + edgeNrmlVect.y ** 2;
|
||||
const pVect = {
|
||||
x: vDotn / denom * edgeNrmlVect.x,
|
||||
y: vDotn / denom * edgeNrmlVect.y
|
||||
};
|
||||
|
||||
const aVect = {
|
||||
x: aDotn / denom * edgeNrmlVect.x,
|
||||
y: aDotn / denom * edgeNrmlVect.y
|
||||
};
|
||||
|
||||
const reverseP = { x: -pVect.x, y: -pVect.y };
|
||||
const reverseA = { x: -aVect.x, y: -aVect.y };
|
||||
|
||||
// add reverseP and v vectors together
|
||||
const prVonNx = reverseP.x + v.x;
|
||||
const prVonNy = reverseP.y + v.y;
|
||||
const prVonNx = reverseP.x + v.x + reverseA.x;
|
||||
const prVonNy = reverseP.y + v.y + reverseA.y;
|
||||
// console.log("velocity vector", velocityVect);
|
||||
// console.log("normal vector", edgeNrmlVect);
|
||||
// console.log("V dot N", vDotn);
|
||||
@@ -612,10 +619,25 @@ const Move = (() => {
|
||||
|
||||
// contact.velocity = { x: prVonNx, y: prVonNy };
|
||||
Velocity[entity_id] = { x: prVonNx, y: prVonNy };
|
||||
console.log("contact.position", contact.position);
|
||||
// drawCircle(contact.position.x, contact.position.y);
|
||||
console.log("current position", px, py);
|
||||
console.log("future position", p);
|
||||
|
||||
// const newV = {
|
||||
// x: vx > 0 && vx + ax <= 0 ? 0 : vx + ax,
|
||||
// y: vy > 0 && vy + ay <= 0 ? 0 : vy + ay
|
||||
// };
|
||||
|
||||
const newP = {
|
||||
x: contact.position.x + elapsed * prVonNx * metersPerMillisecond,
|
||||
y: contact.position.y + elapsed * prVonNy * metersPerMillisecond
|
||||
};
|
||||
console.log("newP", newP);
|
||||
|
||||
Position[entity_id] = newP;
|
||||
}
|
||||
} else {
|
||||
console.log("movi");
|
||||
|
||||
Velocity[entity_id] = { x: v.x, y: v.y };
|
||||
Position[entity_id] = { x: p.x, y: p.y };
|
||||
}
|
||||
@@ -705,10 +727,10 @@ function init() {
|
||||
const mult = 10;
|
||||
|
||||
s.position = { x: 0, y: -10 };
|
||||
s.velocity = { x: -10, y: 20 };
|
||||
// s.velocity = { x: -10, y: 20 };
|
||||
// s.velocity = { x: 10, y: 20 };
|
||||
// s.velocity = { x: -20, y: 40 };
|
||||
// s.velocity = { x: 0, y: 20000 };
|
||||
s.velocity = { x: 0, y: 10 };
|
||||
s.angularVelocity = 0;
|
||||
|
||||
// s. velocity = { x: -5*mult, y: 7*mult };
|
||||
|
||||
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 54 KiB |
Reference in New Issue
Block a user