Back to Community
FluxScript

How do I make a player take damage on collision using FluxScript?

Player should lose health when hitting an enemy

Test Creator
· 7/5/2026 2 1

I'm building a platformer and I want my player to lose 10 health whenever it collides with an enemy object. How do I detect collisions and reduce health in FluxScript? Is there a Node Scripting equivalent?

#FluxScript#Node#Help#Platformer
Appley AI Suggested Solution
Appley AI
AI7/5/2026

💡 Suggested Solution

You can handle player-enemy damage using FluxScript's on collision event, which fires whenever two objects with collision components overlap or contact. The typical pattern is: assign the player and enemy objects distinct tags (e.g. "Player" and "Enemy"), then in the player's script check the collided object's tag and reduce a health variable. Node Scripting has an equivalent "On Collision" event node feeding into a branch and a "Set Variable" node.

Explanation

Collision detection in Appley uses the physics system, so both objects need a Collider component (Box/Sphere/Capsule) and at least one should have a Rigidbody for on collision to fire. Health is usually stored as a numeric property on the player object so it can be referenced by UI and other systems.

Step-by-Step

    1. Select the Player object and add a Collider + Rigidbody if not present.
    1. Tag the player as "Player" and tag enemy objects as "Enemy".
    1. Add a numeric variable/property health to the player (default 100).
    1. Attach a FluxScript (or Node graph) to the player handling the on collision event.
    1. Inside the event, check the other object's tag and subtract 10 from health if it is "Enemy".
    1. Optional: add invulnerability frames (cooldown timer) so the player isn't damaged every frame.

FluxScript Example

// PlayerDamage.flux
property health = 100
property invulnTime = 0

on start
    health = 100
end

on update
    if invulnTime > 0 then
        invulnTime = invulnTime - time.delta
    end
end

on collision(other)
    if other.tag == "Enemy" and invulnTime <= 0 then
        health = health - 10
        invulnTime = 1.0  // 1 second of invulnerability
        if health <= 0 then
            health = 0
            // trigger respawn / game over
            call onPlayerDeath()
        end
    end
end

function onPlayerDeath()
    print("Player defeated!")
    // respawn logic here
end

Node Scripting Equivalent

Node Scripting graph (attach to Player):

  • [On Collision] event node (output: Other Object)
  • [Get Tag] node (input: Other Object) -> string
  • [Branch / If] node: condition (Tag == "Enemy")
  • True branch:
    • [Get Property] health from Self
    • [Subtract] node: health - 10
    • [Set Property] health on Self
    • [Set Property] invulnTime = 1.0 (optional cooldown)
    • [Branch] health <= 0 -> call OnPlayerDeath function node
  • False branch: (empty)

Use a separate [On Update] -> [If invulnTime > 0] -> [Subtract time.delta] -> [Set invulnTime] chain for cooldown handling.

Relevant Documentation

Performance Recommendations

  • Always filter collisions by tag early (first line of the event) to avoid expensive logic running for unrelated collisions.
  • Consider using collision layers/masks in the physics settings to limit which objects can collide - this is cheaper than checking tags in script.
  • Avoid heavy operations (spawning particles, loading assets) directly inside on collision; defer them with a function call or queue.
  • Reuse a single invulnerability timer rather than spawning timers per hit.
  • If you have many enemies, prefer pooling enemy objects rather than instantiating/destroying them on each collision.

Alternative Approaches

  • For trigger-based pickups/hazards, use a Trigger Collider instead of a solid collider so movement isn't blocked.
  • For knockback, apply an impulse to the player's Rigidbody inside the collision handler using physics.applyImpulse.

Best Practices

  • Keep health as a property rather than a local variable so UI elements can bind to it.
  • Centralize death/respawn logic in a function so AI Director, quests, and UI can call it consistently.
  • Test with multiple enemies touching the player simultaneously to ensure cooldown logic works.
  • Use the Tag system consistently; define tags in Project Settings -> Tags.

ℹ️ This response contains suggested ideas. Verify against your specific use case.

0 Replies

Sign in to reply to this discussion.