Pull away from contacted walls
This commit is contained in:
@@ -119,3 +119,8 @@ Delete your `.sitegen_cache` file.
|
||||
* use sitecache with pandoc renderer
|
||||
* draft documents
|
||||
* treesitter highlighting for moonscript
|
||||
|
||||
--
|
||||
|
||||
- Bounce off corners algo
|
||||
- Bounce off multiple simultaneous contacts
|
||||
|
||||
@@ -515,6 +515,10 @@ const Move = (() => {
|
||||
const run = contact.edge.xb-contact.edge.xa;
|
||||
|
||||
drawLine(p.x - v.x, p.y - v.y, p.x, p.y, "blue"); // velocity vector
|
||||
console.log("velocity vector", v.x, v.y);
|
||||
const det = v.x * rise - v.y * run;
|
||||
console.log("DEEEEEEEETTTTTTTTTTTTTTT", det);
|
||||
|
||||
drawLine(contact.edge.xa, contact.edge.ya, contact.edge.xb, contact.edge.yb, "green"); // edge vector
|
||||
|
||||
let newY;
|
||||
@@ -568,13 +572,15 @@ const Move = (() => {
|
||||
newY = prAvy - prBvy;
|
||||
|
||||
drawLine(p.x, p.y, p.x + vec2.rightNormal.x , p.y + vec2.rightNormal.y, "black"); // edge normal vector
|
||||
drawLine(p.x, p.y, p.x + newX , p.y + newY, "blue"); // bounced velocity vector
|
||||
drawLine(p.x, p.y, p.x + newX, p.y + newY, "blue"); // bounced velocity vector
|
||||
|
||||
Velocity[entity_id] = { x: newX, y: newY };
|
||||
|
||||
// TODO can't set position without ball getting stuck
|
||||
// Position[entity_id] = { x: p.x, y: p.y };
|
||||
// Position[entity_id] = contact.position;
|
||||
if (det < 0) {
|
||||
Velocity[entity_id] = { x: newX, y: newY };
|
||||
Position[entity_id] = contact.position;
|
||||
} else {
|
||||
Velocity[entity_id] = { x: v.x, y: v.y };
|
||||
Position[entity_id] = { x: p.x, y: p.y };
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Velocity[entity_id] = { x: v.x, y: v.y };
|
||||
@@ -664,7 +670,7 @@ function init() {
|
||||
started = false;
|
||||
const mult = 10;
|
||||
|
||||
s.position = { x: 0, y: 0 };
|
||||
s.position = { x: 0, y: -10 };
|
||||
// s.velocity = { x: 0, y: -10 };
|
||||
// s.velocity = { x: 10, y: 20 };
|
||||
s.velocity = { x: 0, y: 0 };
|
||||
|
||||
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
Reference in New Issue
Block a user