Skip to content

3. Things to touch ​

An empty floor is a treadmill. Add bodies, then make one of them respond to being looked at and clicked.

Crates ​

ts
import { Box } from '@maomi/sge/object';

for (let i = 0; i < 6; i++) {
  const crate = new Box();
  crate.position = new THREE.Vector3((i % 3) * 1.2 - 1.2, 2 + i, -6);
  fps.add(crate);
}

Six dynamic 1×1×1 crates rain onto the grid and stack. Walk into the pile — the player's body shoves them around; that's the solver, not code you wrote.

An interactable ​

ts
import { LookAtCursor, type Interactable } from '@maomi/sge/cursor';
import type { Player } from '@maomi/sge/player';

class Beacon extends Box implements Interactable {
  interactRange = 6;
  onCursorEnter() { this.three.scale.setScalar(1.15); }
  onCursorLeave() { this.three.scale.setScalar(1); }
  onCursorSelect(player: Player) {
    player.inventory.add('beacon-tag');
  }
}

const beacon = new Beacon();
beacon.position = new THREE.Vector3(4, 0.5, -8);
fps.add(beacon);

fps.add(new LookAtCursor(player));   // after fps.start(player)

The cursor raycasts every frame; inside 6 meters the beacon swells (onCursorEnter), the crosshair grows, and a click hands you the player to do something with — here, dropping a tag into the inventory.

A collision trigger ​

ts
fps.registerCollisionCallback(player, beacon, () => {
  console.log('touched the beacon');
});

Callbacks fire from Bullet's contact manifolds — ghost overlaps included — checked once per frame. In part 4 we'll turn these events into a score on screen.