Scripting: Enemies Health Drop

In this post, we explore the implementation of our health pickup system, covering its spawning, collection mechanics, and contribution to gameplay feedback.

Posted on May 30, 2026
Scripting: Enemies Health Drop

HealthDrop Script

The HealthDrop system is responsible for spawning healing pickups when enemies die or when breakable objects are destroyed. Its goal is to reward the player with health in a visually satisfying way by creating a healing sphere that follows a small drop animation before becoming collectible.

Overview

The HealthDrop system is divided into three main parts:

  • Enemy rewards: Enemies create health pickups when entering their death state.
  • Breakable object rewards: Certain breakable objects can also spawn healing pickups.
  • Pickup behaviour: The pickup itself handles the falling animation, idle floating effect, and player healing.

Complete Flow

1. Enemy dies

When an enemy enters its death state, EnemyDeathState::OnStateEnter() checks whether the enemy should drop health.

If m_shouldDropHealth is enabled, the function calls dropRewards().

2. Spawn position calculation

Inside dropRewards(), a random landing position is generated within a configurable drop radius. The system also calculates an elevated spawn point (arcOrigin) above the enemy so the pickup can perform a small arc animation before landing.

The pickup prefab is then instantiated:

GameObject* pickup = GameObjectAPI::instantiatePrefab(
    m_healthPrefabPath.c_str(),
    arcOrigin,
    Vector3::Zero
);
if (pickup != nullptr)
{
    Script* script = GameObjectAPI::getScript(pickup, "HealthPickup");
    if (script != nullptr)
    {
        HealthPickup* healthPickup = static_cast<HealthPickup*>(script);

        healthPickup->m_healAmount = m_dropHealAmount;
        healthPickup->m_landingPosition = finalPos;
        healthPickup->m_hasCustomSpawnFrom = true;
    }
}

After the prefab is created, the script configures the amount of health that will be restored and the position where the pickup should land.

*3. Breakable objects

The same system is reused by destructible objects through BreakableHealingDrop.

When the object breaks, it delegates the spawning logic to HealthDropSpawner, which creates the pickup and initializes it using setupDrop().

GameObject* pickup = GameObjectAPI::instantiatePrefab(
    prefabPath,
    arcOrigin,
    Vector3::Zero
);

HealthPickup* healthPickup = static_cast<HealthPickup*>(script);
healthPickup->setupDrop(healAmount, landingPosition);

This approach keeps the spawning logic centralized and reusable across different gameplay systems.

Pickup Behaviour

The HealthPickup script controls the entire lifecycle of the healing sphere.

Initialization

When the pickup is spawned, Start() calculates the trajectory needed to reach the landing position generated by the spawner.

This includes calculating horizontal velocity and determining the target landing point.

Falling Animation

During every frame, *Update() *performs the falling movement until the pickup reaches the ground.

void HealthPickup::Update()
{
    fallAnimation();
    idleAnimation();
}

The result is a small arc-like motion that makes the pickup feel more dynamic than simply appearing in place.

Idle State

Once the pickup lands, it transitions to an idle animation. In this state the health sphere gently floats, making it easier for the player to notice and collect.

Player Collection

When the player collides with the pickup,_ OnTriggerEnter()_ checks whether healing is needed and restores health accordingly.

void HealthPickup::OnTriggerEnter(GameObject* player)
{
    damageable->heal(m_healAmount);

}

An optional particle effect can also be spawned to provide visual feedback when the pickup is collected.

Helper Function

To simplify initialization from different systems, the pickup exposes a helper method:

void HealthPickup::setupDrop(
    float healAmount,
    const Vector3& landingPosition)
{ ...}

This function configures the healing value and landing position, allowing enemies and breakable objects to use the same pickup behaviour without duplicating code.

Making Healing More Engaging

The HealthDrop system was created to make combat rewards feel more engaging and visible to the player. Whenever an enemy is defeated, or a breakable object containing health is destroyed, a healing sphere is spawned into the world instead of instantly restoring health.

Rather than appearing statically on the ground, the pickup is launched from the enemy’s position and follows a short arc before landing. This small animation helps draw the player’s attention to the reward and makes enemy deaths feel more impactful.

The system is shared between enemies and destructible objects, allowing both to generate health pickups using the same behaviour. Once the sphere lands, it remains in the world with a floating idle animation until the player collects it, at which point it restores health and optionally triggers visual effects.

This approach not only provides a clear reward for defeating enemies but also encourages players to move around the environment and actively collect resources during gameplay.

Related Posts

Learn more about the behind-the-scenes of Ravenwhisp's development.