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).
Extends
Section titled “Extends”Methods
Section titled “Methods”add()?
Section titled “add()?”
optionaladd(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).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”destroy()?
Section titled “destroy()?”
optionaldestroy(this):void
Defined in: packages/threeplay/src/core/types.ts:69
Called when the object is destroyed or the component removed.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”fixedUpdate()?
Section titled “fixedUpdate()?”
optionalfixedUpdate(this):void
Defined in: packages/threeplay/src/core/types.ts:67
Called at the fixed physics rate (50 Hz by default).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”heal()
Section titled “heal()”heal(
amount?):void
Defined in: packages/threeplay/src/plugins/gameplay/types.ts:20
Adds hit points (default 1, clamped to maxHp) and emits "heal".
Parameters
Section titled “Parameters”amount?
Section titled “amount?”number
Returns
Section titled “Returns”void
hurt()
Section titled “hurt()”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.
Parameters
Section titled “Parameters”amount?
Section titled “amount?”number
Returns
Section titled “Returns”void
inspect()?
Section titled “inspect()?”
optionalinspect(this):string|null|undefined
Defined in: packages/threeplay/src/core/types.ts:71
Short status line shown by the debug inspector.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”string | null | undefined
Inherited from
Section titled “Inherited from”onDeath()
Section titled “onDeath()”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).
Parameters
Section titled “Parameters”() => void
Returns
Section titled “Returns”onHeal()
Section titled “onHeal()”onHeal(
fn):EventController
Defined in: packages/threeplay/src/plugins/gameplay/types.ts:26
Runs after every heal().
Parameters
Section titled “Parameters”(amount) => void
Returns
Section titled “Returns”onHurt()
Section titled “onHurt()”onHurt(
fn):EventController
Defined in: packages/threeplay/src/plugins/gameplay/types.ts:24
Runs after every hurt().
Parameters
Section titled “Parameters”(amount) => void
Returns
Section titled “Returns”setHP()
Section titled “setHP()”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.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
update()?
Section titled “update()?”
optionalupdate(this):void
Defined in: packages/threeplay/src/core/types.ts:65
Called once per frame.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Properties
Section titled “Properties”conflicts?
Section titled “conflicts?”
optionalconflicts?:string[]
Defined in: packages/threeplay/src/core/types.ts:61
Ids of components that can’t be on the same object (checked both ways).
Inherited from
Section titled “Inherited from”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.
Overrides
Section titled “Overrides”maxHp:
number
Defined in: packages/threeplay/src/plugins/gameplay/types.ts:16
Upper limit of hp and of heal().
require?
Section titled “require?”
optionalrequire?:string[]
Defined in: packages/threeplay/src/core/types.ts:59
Ids of components that must be present on the object.