WIP: Velocity while in contact with edge
This commit is contained in:
@@ -125,7 +125,7 @@
|
||||
<!-- <polygon class="wall" points="-10,50 -3,50 -3,60 -10,60" /> -->
|
||||
|
||||
<!-- <polygon class="wall" points="20,-50 10,-50 10,-60 20,-60" /> -->
|
||||
<polygon class="wall" points="-10,10 10,10 10,20 -10,20" />
|
||||
<polygon class="wall" points="-10,10 10,10 10,40 -10,40" />
|
||||
|
||||
<!-- <polygon class="wall" points="-20,-50 -10,-50 -10,-60 -20,-60" /> -->
|
||||
<!-- <polygon class="wall" points="20,50 10,50 10,60 20,60" /> -->
|
||||
@@ -493,34 +493,18 @@ const Move = (() => {
|
||||
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
let posP;
|
||||
const contact = contacts[0];
|
||||
|
||||
if (contact.corner) {
|
||||
posP = cornerContactPosition(p.x, p.y, px, py, contact.corner, s.radius);
|
||||
Velocity[entity_id] = { x: 0, y: 0 };
|
||||
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("contact", contact);
|
||||
// posP = edgeContactPosition(p.x, p.y, px, py, contact.edge, s.radius);
|
||||
// console.log("position calculated by edgeContactPosition", posP);
|
||||
posP = contact.position;
|
||||
|
||||
// console.log("edge contact position current", posP);
|
||||
// const velBeforeColl = { vx: Velocity[entity_id].x, vy: Velocity[entity_id].y };
|
||||
|
||||
// console.log("velocity before collision", velBeforeColl);
|
||||
|
||||
const { xa, ya, xb, yb } = contact.edge;
|
||||
|
||||
const positionSeg = { x1: px, y1: py, x2: p.x, y2: p.y };
|
||||
const edgeSeg = { x1: xa, y1: ya, x2: xb, y2: yb };
|
||||
|
||||
console.log("CURRENT POSITION", px, py);
|
||||
console.log("INTENDED POSITION", p.x, p.y);
|
||||
console.log("CONTACT POSITION", contact.position);
|
||||
|
||||
// if (px === posP.x && py === posP.y) {
|
||||
// const m1 = slope({ xa: px, ya: py, xb: p.x, yb: p.y });
|
||||
if (contact.edge.ya === contact.edge.yb && contact.edge.xa < contact.edge.xb) {
|
||||
console.log("ON A FLAT EDGE");
|
||||
// Velocity[entity_id] = { x: velX, y: velY };
|
||||
if (contact.edge.ya === contact.edge.yb) {
|
||||
if (contact.edge.xa < contact.edge.xb) {
|
||||
if (v.y <= 0) {
|
||||
Velocity[entity_id] = { x: v.x, y: v.y };
|
||||
Position[entity_id] = { x: p.x, y: p.y };
|
||||
@@ -528,54 +512,17 @@ const Move = (() => {
|
||||
Velocity[entity_id] = { x: v.x, y: 0 };
|
||||
Position[entity_id] = { x: p.x, y: contact.position.y };
|
||||
}
|
||||
// Velocity[entity_id].x = v.x;
|
||||
|
||||
// Position[entity_id] = { x: p.x, y: p.y };
|
||||
} else if (contact.edge.xa > contact.edge.xb) {
|
||||
if (v.y <= 0) {
|
||||
Velocity[entity_id] = { x: v.x, y: 0 };
|
||||
Position[entity_id] = { x: p.x, y: contact.position.y };
|
||||
} else if (v.y > 0) {
|
||||
Velocity[entity_id] = { x: v.x, y: v.y };
|
||||
Position[entity_id] = { x: p.x, y: p.y };
|
||||
}
|
||||
}
|
||||
// const m1 = slope({ xa: vx, ya: vy, xb: v.x, yb: v.y });
|
||||
// const m2 = slope(contact.edge);
|
||||
// const m2 = 1/-slope(contact.edge); //normal??
|
||||
|
||||
// we need the angle between the velocity and normal vector, no?
|
||||
|
||||
// const theta = Math.atan((m1-m2) / (1+m2*m2));
|
||||
// const velX = v.x * Math.sin(theta);
|
||||
// const velY = v.y * Math.cos(theta);
|
||||
// console.log("vvvvvvvvvvvvvvvvvvvv", v);
|
||||
// console.log("theta", theta);
|
||||
|
||||
// console.log("theta", theta, "velX", velX.toFixed(15), "velY", velY.toFixed(15));
|
||||
|
||||
// i need the normal force to push back
|
||||
|
||||
// Velocity[entity_id] = { x: velX, y: velY };
|
||||
// Position[entity_id] = { x: p.x, y: p.y };
|
||||
// } else {
|
||||
// Velocity[entity_id] = { x: 0, y: 0 };
|
||||
// Position[entity_id] = { x: posP.x, y: posP.y };
|
||||
// }
|
||||
|
||||
// console.log("POSITIONSEG", positionSeg);
|
||||
// console.log("EDGESEG", edgeSeg);
|
||||
}
|
||||
}
|
||||
|
||||
// we need to map velocity in segments
|
||||
// Velocity[entity_id] = { x: 0, y: 0 };
|
||||
// Position[entity_id] = { x: posP.x, y: posP.y };
|
||||
|
||||
// s.node.style.transform = `translate(${Position[entity_id].x}px, ${Position[entity_id].y}px)`;
|
||||
// } else if (current && s.collision) {
|
||||
// console.log("2222222222222222222222222222222");
|
||||
|
||||
// if (s.isLanded && s.velocity.y < 0) {
|
||||
// s.gearDown = false;
|
||||
// s.isLanded = false;
|
||||
// s.position = { x: p.x, y: p.y };
|
||||
// s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
|
||||
// s.collision = null;
|
||||
// } else {
|
||||
// s.velocity = { x: 0, y: 0 };
|
||||
// }
|
||||
} else {
|
||||
Velocity[entity_id] = { x: v.x, y: v.y };
|
||||
Position[entity_id] = { x: p.x, y: p.y };
|
||||
|
||||
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 48 KiB |
Reference in New Issue
Block a user