Skip to content

Commit

Permalink
fix: Fix issues with the ship sizing algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Oct 19, 2024
1 parent d7c2864 commit 31e1524
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions server/src/spawners/ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export async function spawnShip(
);
size.multiplyScalar(template.length || 1);
entity.addComponent("size", {
length: size.z,
width: size.x,
height: size.y,
length: size.x,
width: size.y,
height: size.z,
});

entity.addComponent("mass", { mass: template.mass });
Expand Down Expand Up @@ -420,5 +420,10 @@ async function getMeshSize(url: string | null): Promise<Vector3> {
if (!gltf) return new Vector3();
const box = new Box3().setFromObject(gltf.scene.children[0]);

return box.getSize(new Vector3());
const vector = box.getSize(new Vector3()).normalize();
const { x } = vector;
// Rearrange the vector to match the orientation of the ship
vector.normalize().multiplyScalar(1 / x);

return vector;
}

0 comments on commit 31e1524

Please sign in to comment.