server/src/game/capsule.object.ts

21 lines
637 B
TypeScript

import { Vector3 } from 'three';
import { Brick } from './brick.object';
import type Rapier from '@dimforge/rapier3d-compat';
export class Capsule extends Brick {
public objectType = 'Capsule';
public name = this.objectType;
protected override createCollider(
factory: typeof Rapier,
world: Rapier.World,
body?: Rapier.RigidBody,
) {
const scale = this.getWorldScale(new Vector3());
const height = Math.abs(scale.y) / 2;
const radius = (Math.abs(scale.x) + Math.abs(scale.z)) / 2;
const collider = factory.ColliderDesc.capsule(height, radius);
return world.createCollider(collider, body);
}
}