Add player collision module

This commit is contained in:
2026-04-04 15:52:46 +02:00
parent 3fdbc002b6
commit 16a7b4e7e2

View File

@@ -0,0 +1,50 @@
import type { Vec3 } from "../core/vector";
export type FirstPersonPlayerShape =
| {
mode: "capsule";
radius: number;
height: number;
eyeHeight: number;
}
| {
mode: "box";
size: Vec3;
eyeHeight: number;
}
| {
mode: "none";
eyeHeight: number;
};
export interface ResolvedPlayerMotion {
feetPosition: Vec3;
grounded: boolean;
collidedAxes: {
x: boolean;
y: boolean;
z: boolean;
};
}
export const FIRST_PERSON_PLAYER_SHAPE: FirstPersonPlayerShape = {
mode: "capsule",
radius: 0.3,
height: 1.8,
eyeHeight: 1.6
};
export function getFirstPersonPlayerEyeHeight(shape: FirstPersonPlayerShape): number {
return shape.eyeHeight;
}
export function getFirstPersonPlayerHeight(shape: FirstPersonPlayerShape): number | null {
switch (shape.mode) {
case "capsule":
return shape.height;
case "box":
return shape.size.y;
case "none":
return null;
}
}