This commit is contained in:
Schluffe
2026-06-28 16:23:38 +02:00
parent f8efda0ada
commit 135b7c3042
4 changed files with 43 additions and 41 deletions
+11 -11
View File
@@ -412,7 +412,7 @@ function createCollision(): Collision {
};
}
const relVelocity = createVector();
const relativeVel = createVector();
export function moveAndCollide(
id: string,
velocity: Vector,
@@ -420,7 +420,8 @@ export function moveAndCollide(
): Array<Collision> {
const colliders = $<Collider>("collider")!;
const positions = $<Vector>("position")!;
const velocities = $<Vector>("velocity");
const velocities = $<Vector>("velocity")!;
const selfColl = colliders.get(id)!.value;
const selfPos = positions.get(id)!.value;
@@ -434,13 +435,12 @@ export function moveAndCollide(
const otherColl = collider.value;
const otherPos = positions.get(cid)!.value;
const otherVel = velocities?.get(cid)?.value ?? ZERO;
const otherVel = velocities.get(cid)?.value ?? ZERO;
relVelocity.x = velocity.x - otherVel.x;
relVelocity.y = velocity.y - otherVel.y;
relativeVel.x = velocity.x - otherVel.x;
relativeVel.y = velocity.y - otherVel.y;
// no relative motion
if (relVelocity.x === 0 && relVelocity.y === 0) {
if (relativeVel.x === 0 && relativeVel.y === 0) {
continue;
}
@@ -449,7 +449,7 @@ export function moveAndCollide(
collision,
selfColl,
selfPos,
relVelocity,
relativeVel,
otherColl,
otherPos,
delta,
@@ -467,7 +467,7 @@ export function moveAndCollide(
collision,
selfColl,
selfPos,
relVelocity,
relativeVel,
otherColl,
otherPos,
delta,
@@ -479,7 +479,7 @@ export function moveAndCollide(
collision,
selfColl,
selfPos,
relVelocity,
relativeVel,
otherColl,
otherPos,
delta,
@@ -491,7 +491,7 @@ export function moveAndCollide(
collision,
selfColl,
selfPos,
relVelocity,
relativeVel,
otherColl,
otherPos,
delta,