followAi
require
sight()agent()parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
retreat | boolean | true |
example
followAi({ retreat: true}),function followAi(p) { const param = { retreat: true, ...p } return { require: ["sight", "agent"], id: "follow", retreatTarget: null, add() { requestAnimationFrame(() => this.retreatTarget = vec2(this.pos)) if (param.retreat) this.onTargetReached(() => this.setTarget(this.retreatTarget)) }, update() { const target = this.getClosestTarget(param) if (target) this.setTarget(target.pos) else if (param.retreat) this.setTarget(this.retreatTarget) }, }}