CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Health
inherits: Node
Tracks the health of an entity.
Tracks the health of an entity and emits various signals when changes to current occur through damage() or heal() function calls.
Add this component as a direct child of an entity or by setting the exported variable. The entity will be sent with each signal to associate an entity with the health component that was affected.
The component can be used standalone or paired with a HurtBox2D/HurtBox3D to automatically invoke damage() and heal() when collisions are detected by HitBox2D/HitBox3D or HitScan2D/HitScan3D components.
type | name | value |
---|---|---|
int | DEFAULT_MAX | 100 |
type | name | default |
---|---|---|
int | current | DEFAULT_MAX |
int | max | DEFAULT_MAX |
Node | entity | owner |
bool | damageable | true |
bool | healable | true |
bool | killable | true |
bool | revivable | true |
return | function |
---|---|
void | damage() |
void | heal() |
float | percent() |
void | kill() |
void | fill_health() |
bool | is_dead() |
bool | is_alive() |
bool | is_full() |
damaged(entity: Node, amount: int, applied: int, multiplier: float)
Emitted after damage is applied to current health.
- entity is the Node in the entity property.
-
amount is the amount specified when
damage()
is called. -
applied is the amount current was actually reduced by. Only different when
amount
would have made current negative. - multiplier is the value amount is multiplied by to determine how much to apply.
died(entity: Node)
Emitted after damage is applied to current health and death has occured.
- entity is the Node in the entity property.
healed(entity: Node, amount: int, applied: int, multiplier: float)
Emitted after healing is applied to current health.
- entity is the Node in the entity property.
-
amount is the amount specified when
heal()
is called. -
applied is the amount current was actually increased by. Only different when
amount
would have made current greater than max. - multiplier is the value amount is multiplied by to determine how much to apply.
revived(entity: Node)
Emitted after healing is applied to current health when entity was previously dead.
- entity is the Node in the entity property.
already_dead(entity: Node)
Emitted when attempting to damage an entity that is already dead.
- entity is the Node in the entity property.
already_full(entity: Node)
Emitted when attempting to heal an entity that is already full.
- entity is the Node in the entity property.
first_hit(entity: Node)
Emitted when damage was applied to an entity that had full health.
- entity is the Node in the entity property.
full(entity: Node)
Emitted when healing was applied to an entity that now has full health.
- entity is the Node in the entity property.
not_damageable(entity: Node)
Emitted when attempting to damage to an entity and damageable is set to false
.
- entity is the Node in the entity property.
not_healable(entity: Node)
Emitted when attempting to heal an entity and healable is set to false
.
- entity is the Node in the entity property.
not_killable(entity: Node)
Emitted when attempting to damage an entity that would kill them and killable is set to false
.
- entity is the Node in the entity property.
not_revivable(entity: Node)
Emitted when attempting to heal and entity that is dead and revivable is set to false
.
- entity is the Node in the entity property.
- This action will apply damage and reduce current health.
- This action will apply healing and increase current health.
@export var current: int = DEFAULT_MAX
The current amount of health. Value is clamped in setter between [0, max]
@export var max: int = MAX_DEFAULT
The maximum amount of health. Value cannot be less than 1, setter will update current to remain in the bound of a new max.
@export var entity: Node = owner
The Node
this component is associated with. All signals will pass this entity so listeners will know which entity's health was affected. If this health component isn't a direct child of the entity it is associated with this variable can be set to any desired Node.
@export var damageable: bool = true
Damage can be applied when this is true
.
@export var healable: bool = true
Healing can be applied when this is true
.
@export var killable: bool = true
entity can be killed when this is true
.
@export var revivable: bool = true
entity can be revived when this is true
.
damage(amount: int, multiplier: float = 1.0) -> void
Decrement current if applicable and emit signals that apply.
heal(amount: int, multiplier: float = 1.0) -> void
Increment current if applicable and emit signals that apply.
percent() -> float
Returns the calculated percent current divided by max. Perfect for updating progress bars.
kill() -> void
Decrement current to 0 if and emit signals that apply.
fill_health() -> void
Increment current to max and emit signals that apply.
is_dead() -> bool
Returns true
when current is 0 and killable is true
.
is_alive() -> bool
Returns true
when is_dead() is false
.
is_full() -> bool