WIP: Bouncing working but still not perfect
This commit is contained in:
@@ -556,22 +556,22 @@ const Move = (() => {
|
|||||||
|
|
||||||
if (contact.corner) {
|
if (contact.corner) {
|
||||||
contact.position = cornerContactPosition(p.x, p.y, px, py, contact.corner, s.radius);
|
contact.position = cornerContactPosition(p.x, p.y, px, py, contact.corner, s.radius);
|
||||||
console.log("contact position", contact.position);
|
// console.log("contact position", contact.position);
|
||||||
drawLine(contact.position.x, contact.position.y, contact.position.x + vx, contact.position.y + vy, "blue");
|
// drawLine(contact.position.x, contact.position.y, contact.position.x + vx, contact.position.y + vy, "blue");
|
||||||
|
|
||||||
const contactV = { x: contact.position.y - contact.corner.y, y: contact.position.x - contact.corner.x };
|
const contactV = { x: contact.position.y - contact.corner.y, y: contact.position.x - contact.corner.x };
|
||||||
console.log("contactV", contactV);
|
// console.log("contactV", contactV);
|
||||||
const normalVect = { x: contact.position.x - contact.corner.x, y: contact.position.y - contact.corner.y };
|
const normalVect = { x: contact.position.x - contact.corner.x, y: contact.position.y - contact.corner.y };
|
||||||
console.log("normal vector", normalVect);
|
// console.log("normal vector", normalVect);
|
||||||
drawLine(contact.corner.x, contact.corner.y, contact.corner.x + normalVect.x, contact.corner.y + normalVect.y, "black");
|
// drawLine(contact.corner.x, contact.corner.y, contact.corner.x + normalVect.x, contact.corner.y + normalVect.y, "black");
|
||||||
|
|
||||||
const tangentVect = { x: normalVect.y, y: -normalVect.x };
|
const tangentVect = { x: normalVect.y, y: -normalVect.x };
|
||||||
drawLine(contact.position.x, contact.position.y, contact.position.x + tangentVect.x, contact.position.y + tangentVect.y, "green");
|
// drawLine(contact.position.x, contact.position.y, contact.position.x + tangentVect.x, contact.position.y + tangentVect.y, "green");
|
||||||
contact.velocity = bounceVector(v, tangentVect.x, tangentVect.y);
|
contact.velocity = bounceVector(v, tangentVect.x, tangentVect.y);
|
||||||
|
|
||||||
console.log("tangent vector", tangentVect);
|
// console.log("tangent vector", tangentVect);
|
||||||
|
|
||||||
drawLine(contact.position.x, contact.position.y, contact.position.x + contact.velocity.x, contact.position.y + contact.velocity.y, "blue");
|
// drawLine(contact.position.x, contact.position.y, contact.position.x + contact.velocity.x, contact.position.y + contact.velocity.y, "blue");
|
||||||
|
|
||||||
// Velocity[entity_id] = { x: 0, y: 0 };
|
// Velocity[entity_id] = { x: 0, y: 0 };
|
||||||
Velocity[entity_id] = contact.velocity;
|
Velocity[entity_id] = contact.velocity;
|
||||||
@@ -585,23 +585,26 @@ const Move = (() => {
|
|||||||
const rise = contact.edge.yb-contact.edge.ya;
|
const rise = contact.edge.yb-contact.edge.ya;
|
||||||
const run = contact.edge.xb-contact.edge.xa;
|
const run = contact.edge.xb-contact.edge.xa;
|
||||||
|
|
||||||
drawLine(p.x - v.x, p.y - v.y, p.x, p.y, "blue"); // velocity vector
|
// drawLine(p.x - v.x, p.y - v.y, p.x, p.y, "blue"); // velocity vector
|
||||||
const det = v.x * rise - v.y * run;
|
const det = v.x * rise - v.y * run;
|
||||||
|
|
||||||
drawLine(contact.edge.xa, contact.edge.ya, contact.edge.xb, contact.edge.yb, "green"); // edge vector
|
// drawLine(contact.edge.xa, contact.edge.ya, contact.edge.xb, contact.edge.yb, "green"); // edge vector
|
||||||
|
|
||||||
// contact.velocity = { x: prAvx - prBvx, y: prAvy - prBvy };
|
// contact.velocity = { x: prAvx - prBvx, y: prAvy - prBvy };
|
||||||
contact.velocity = bounceVector(v, run, rise);
|
contact.velocity = bounceVector(v, run, rise);
|
||||||
|
|
||||||
// edge normal vector
|
// edge normal vector
|
||||||
drawLine(p.x, p.y, p.x + contact.velocity.vec2.rightNormal.x , p.y + contact.velocity.vec2.rightNormal.y, "black");
|
// drawLine(p.x, p.y, p.x + contact.velocity.vec2.rightNormal.x , p.y + contact.velocity.vec2.rightNormal.y, "black");
|
||||||
// bounced velocity vector
|
// bounced velocity vector
|
||||||
drawLine(p.x, p.y, p.x + contact.velocity.x, p.y + contact.velocity.y, "blue");
|
// drawLine(p.x, p.y, p.x + contact.velocity.x, p.y + contact.velocity.y, "blue");
|
||||||
|
|
||||||
if (det < 0) {
|
if (det < 0) {
|
||||||
|
// moving towards edge
|
||||||
Velocity[entity_id] = contact.velocity;
|
Velocity[entity_id] = contact.velocity;
|
||||||
|
// Velocity[entity_id] = { x: 0, y: 0 };
|
||||||
Position[entity_id] = contact.position;
|
Position[entity_id] = contact.position;
|
||||||
} else {
|
} else {
|
||||||
|
// moving away from edge
|
||||||
Velocity[entity_id] = { x: v.x, y: v.y };
|
Velocity[entity_id] = { x: v.x, y: v.y };
|
||||||
Position[entity_id] = { x: p.x, y: p.y };
|
Position[entity_id] = { x: p.x, y: p.y };
|
||||||
}
|
}
|
||||||
@@ -694,10 +697,10 @@ function init() {
|
|||||||
started = false;
|
started = false;
|
||||||
const mult = 10;
|
const mult = 10;
|
||||||
|
|
||||||
s.position = { x: 0, y: -10 };
|
s.position = { x: 0, y: -8 };
|
||||||
// s.velocity = { x: 0, y: -10 };
|
// s.velocity = { x: 0, y: -10 };
|
||||||
// s.velocity = { x: 10, y: 20 };
|
// s.velocity = { x: 10, y: 20 };
|
||||||
s.velocity = { x: 5, y: 0 };
|
s.velocity = { x: 10, y: 20 };
|
||||||
s.angularVelocity = 0;
|
s.angularVelocity = 0;
|
||||||
|
|
||||||
// s. velocity = { x: -5*mult, y: 7*mult };
|
// s. velocity = { x: -5*mult, y: 7*mult };
|
||||||
@@ -1264,7 +1267,7 @@ function updateShip(s, elapsed) {
|
|||||||
current = s.collision;
|
current = s.collision;
|
||||||
|
|
||||||
s.collision = detectCollision([px, py], p, s.velocity, s.radius, map, s.gearDown);
|
s.collision = detectCollision([px, py], p, s.velocity, s.radius, map, s.gearDown);
|
||||||
if (!current && s.collision) console.log("COLLISION", s.collision);
|
// if (!current && s.collision) console.log("COLLISION", s.collision);
|
||||||
|
|
||||||
legs.style.display = s.gearDown ? "initial" : "none";
|
legs.style.display = s.gearDown ? "initial" : "none";
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
Reference in New Issue
Block a user