b3d-npc

Puts a mind in a biped. Nest it in a <tosi-b3d-biped> and the biped stands guard (or wanders), is oblivious until it notices the player, then chases and attacks within reach; it loses them, searches, and goes back. A noise sends it to look. It drives the biped exactly as a player does, with the same ControlInput (AI-DESIGN: an AI is an input provider), so anything a player's biped can do, an NPC's can.

The decisions are npc-brain's and the senses sensorium's, both pure and seeded. This element gives them a body:

Give the biped health and it can be killed: it plays its death and stops.

import { b3dBiped, b3dNpc, ualAnimationStates, assetUrl } from 'tosijs-3d'

b3dBiped(
  {
    url: assetUrl('quaternius/UAL1_core.glb', 5),
    animationStates: ualAnimationStates([{ name: 'attack', animation: 'Sword_Attack', loop: false }]),
    x: 10, z: -10, ry: -35, health: 60,
  },
  b3dNpc({ attackDamage: 20 })
)

The Biped Playground has one standing guard past the crates.

Attributes

Attribute Default Description
target 'player' Who it is after: the player (the input focus's biped)
skill 0 0..1: how often it thinks again, so how fast it reacts and how fresh its idea of where you are (dumb is the default)
sightRange 50 Metres it notices you in front
sightDeg 180 How wide "in front" is
nearRange 10 Metres it notices you behind it
stealth 0.33 What crouching multiplies those by
hearing 1 Multiplies how far a noise carries to it
wanderRadius 0 Metres it wanders from where it started; 0 stands guard
memory 6 Seconds it remembers you after losing you
attackRange 1.4 Metres it attacks from
attackDamage 20 What a blow does
attackCooldown 1.6 Seconds between attacks
attackState 'attack' The biped state its attack plays
walkPace 0.3 Forward input while walking (0..1)
runPace 0.7 Forward input while chasing
seed 1 Its wandering and timing: the same seed, the same behaviour

patrol (a property, not an attribute: b3dNpc({ patrol: [{ x, z }, …] })) is a route it walks in a loop, pausing at each point.

debugState reads what it is doing: { mode, alertness, sees, senses, heard }.