WWIP
This commit is contained in:
+34
-13
@@ -270,21 +270,42 @@ export function moveAndSlide(
|
|||||||
velocity: Vector,
|
velocity: Vector,
|
||||||
delta: number,
|
delta: number,
|
||||||
): void {
|
): void {
|
||||||
const collisions = moveAndCollide(id, velocity, delta);
|
let timeLeft = 1;
|
||||||
for (const collision of collisions) {
|
const aabb = $<Collider>("collider").get(id)!.value.aabb;
|
||||||
const time = collision.time;
|
const position = $<Vector>("position").get(id)!.value;
|
||||||
if (time === -Infinity) {
|
|
||||||
continue; // TODO
|
for (let i = 0; i < 4; i++) {
|
||||||
|
const collisions = moveAndCollide(id, velocity, delta);
|
||||||
|
if (collisions.length < 1) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
let closest = collisions[0];
|
||||||
// const ts = Math.min(0, time - 0.001);
|
for (const collision of collisions) {
|
||||||
// velocity.x += velocity.x * ts;
|
if (collision.time < closest.time) {
|
||||||
// velocity.y += velocity.y * ts;
|
closest = collision;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const dot = getDotProduct(velocity, collision.normal);
|
const time = closest.time;
|
||||||
const rt = 1 - time + 0.001;
|
if (time === -Infinity) {
|
||||||
velocity.x -= collision.normal.x * dot * rt;
|
break; // TODO
|
||||||
velocity.y -= collision.normal.y * dot * rt;
|
}
|
||||||
|
|
||||||
|
const scale = Math.max(0, time - 0.001);
|
||||||
|
aabb.position.x += velocity.x * (delta * timeLeft) * scale;
|
||||||
|
aabb.position.y += velocity.y * (delta * timeLeft) * scale;
|
||||||
|
|
||||||
|
const dot = getDotProduct(velocity, closest.normal);
|
||||||
|
velocity.x -= closest.normal.x * dot;
|
||||||
|
velocity.y -= closest.normal.y * dot;
|
||||||
|
|
||||||
|
timeLeft *= 1 - time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
velocity.x *= timeLeft;
|
||||||
|
velocity.y *= timeLeft;
|
||||||
|
|
||||||
|
position.x = aabb.position.x;
|
||||||
|
position.y = aabb.position.y;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user