HurtBox2D - cluttered-code/godot-health-hitbox-hurtbox GitHub Wiki

inspector

inherits: Area2D

Enables collision detection and acts as a passthrough for a Health component.

Description

This component will enable HitBox2D and HitScan2D components to detect collisions and automatically apply their DAMAGE or HEAL to the Health component using the HurtBox as a passthrough.

Multiple HurtBox componentes can be associated with the same Health component to better fit a model or represent separate parts like arms and legs.

damage_multiplier and heal_multiplier can be used to dampen or exaggerate the amount applied. Classic examples would be a headshot HurtBox with a damage_multiplier of 2.0 or a piece of armor with a damage_multiplier of 0.8.

[!warning] The Collison Layer needs to be set so HitBox2D and HitScan2D can detect this HurtBox. There is not need to set the Collision Mask, this component doesn't need to detect collisions with other components and will improve performance.

Tutorials

Properties

type name default
Health health null
float damage_multiplier 1.0
float heal_multiplier 1.0
bool heal_on_damage false
bool damage_on_heal false

Methods

return function
void damage()
void heal()

Property Descriptions

health

@export var health: Health = null

    REQUIRED The Health component this component is detecting collisions for and relaying function calls to.

damage_multiplier

@export var damage_multiplier: float = 1.0

    The multiplier to dampen or exaggerate damage amount passed through this component. A HurtBox representing a head shot might have a value greater than 1; like 2.0. A piece of armor might have a value less than 1, such as 0.8, or a shield that blocks all damage 0.0. To reverse the affects of damage and apply healing set a negative value -1.0.

heal_multiplier

@export var heal_multiplier: float = 1.0

    The multiplier to dampen or exaggerate heal amount passed through this component.

heal_on_damage

@export var heal_on_damage: bool = false

    This will redirect damage to Health.heal() instead of Health.damage().

damage_on_heal

@export var damage_on_heal: bool = false

    This will redirect healing to Health.damage() instead of Health.heal().

Method Descriptions

damage

damage(amount: int) -> void

    Multipies the specified amount by damage_multiplier and passed to Health.damage() or Health.heal() as needed.

heal

heal(amount: int) -> void

    Multipies the specified amount by heal_multiplier and passed to Health.heal() or Health.damage() as needed.