Skip to content

HealthComp

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:8

Fields added by health(). Events are object events: "hurt" (amount), "heal" (amount) and "death", also reachable with k.on("death", tag, fn).

optional add(this): void

Defined in: packages/threeplay/src/core/types.ts:63

Called when the object enters the scene (or when used on a live object).

GameObj

void

Comp.add


optional destroy(this): void

Defined in: packages/threeplay/src/core/types.ts:69

Called when the object is destroyed or the component removed.

GameObj

void

Comp.destroy


optional fixedUpdate(this): void

Defined in: packages/threeplay/src/core/types.ts:67

Called at the fixed physics rate (50 Hz by default).

GameObj

void

Comp.fixedUpdate


heal(amount?): void

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:20

Adds hit points (default 1, clamped to maxHp) and emits "heal".

number

void


hurt(amount?): void

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:18

Removes hit points (default 1), emits "hurt", then "death" if hp reached 0.

number

void


optional inspect(this): string | null | undefined

Defined in: packages/threeplay/src/core/types.ts:71

Short status line shown by the debug inspector.

GameObj

string | null | undefined

Comp.inspect


onDeath(fn): EventController

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:28

When hp reaches 0 (fires once until hp is above 0 again).

() => void

EventController


onHeal(fn): EventController

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:26

Runs after every heal().

(amount) => void

EventController


onHurt(fn): EventController

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:24

Runs after every hurt().

(amount) => void

EventController


setHP(hp): void

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:22

Sets hp (clamped to 0…maxHp) without hurt/heal events; emits "death" at 0.

number

void


optional update(this): void

Defined in: packages/threeplay/src/core/types.ts:65

Called once per frame.

GameObj

void

Comp.update

optional conflicts?: string[]

Defined in: packages/threeplay/src/core/types.ts:61

Ids of components that can’t be on the same object (checked both ways).

Comp.conflicts


hp: number

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:14

Current hit points, always within 0…maxHp. Assigning to it (obj.hp -= 1) behaves like HealthComp.setHP.


id: "health"

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:9

Unique name. Two components with the same id replace each other.

Comp.id


maxHp: number

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:16

Upper limit of hp and of heal().


optional require?: string[]

Defined in: packages/threeplay/src/core/types.ts:59

Ids of components that must be present on the object.

Comp.require