Skip to content

Health, damage, weapons, and enemies

Combat is assembled from focused components. The shared runtime decides every hit, cooldown, health change, death, projectile, and enemy target. A player's browser sends controls only.

Give an object health

Select an object and add Health. Set its maximum and starting health, invulnerability time, and team:

  • Player is normally used by playable characters.
  • Enemy is normally used by hostile NPCs.
  • Neutral is useful for destructible world objects.

Turn on Destroy on zero for enemies or props that should disappear. Leave it off on a player to restore health and respawn at the current checkpoint.

Make a damage zone

Add a Sensor Collider, then add Contact damage. Choose the damage amount, fixed-tick cooldown, knockback, and target teams. A 30-tick cooldown is half a second because authoritative worlds run at 60 ticks per second.

The ready-made Damage zone piece already targets players. Resize its Visual and Collider independently when you need a different look or hit area.

Give a player a weapon

Add Health, then add Projectile weapon to a Player object. If the project does not have a Projectile prefab, Workshop creates a safe Basic projectile prefab for you. Use the prefab editor to change its Visual, Sensor Collider, and Projectile settings.

Players attack with F by default. They can remap Attack in Settings. The current movement direction aims a top-down weapon; a platformer faces left or right. Turn on Automatic to fire repeatedly while Attack is held. Otherwise, each press fires once.

Build a chasing enemy

Add the ready-made Chase enemy piece, or attach Transform, Rigidbody, Collider, Health, and Chase AI to an object. Choose its target team, movement mode, detection range, stop range, and speed. Add Projectile weapon if it should fire while pursuing.

Chase AI chooses the nearest living target deterministically. It does not find routes around walls or run an arbitrary behavior tree, so build clear encounter spaces and use colliders to shape movement.

Projectiles

A Projectile prefab root needs Transform, Rigidbody, a Sensor Collider, and Projectile. Its team prevents it from damaging the owner team. Speed, damage, lifetime, extra pierced targets, and knockback are bounded and authoritative. Continuous collision detection is recommended for fast projectiles.

RiftScript events

An object with controlled behavior can respond to:

text
riftscript 1;

event damaged {
  score.add(1);
}

event death {
  world.destroy();
}

These handlers react to a trusted runtime decision. RiftScript does not calculate hits or accept damage claims from the browser.

Common problems

  • A weapon must be attached to a Player or Chase AI object with a Transform.
  • A Projectile must be the root of the prefab selected by a weapon and must use a Sensor Collider.
  • Chase AI needs Transform, Rigidbody, Collider, and Health and cannot share control with Player or Patrol.
  • Starting health cannot exceed maximum health; the stop range cannot exceed the detection range.
  • Combat health is restored in room snapshots and replays, but it is not persisted between separate visits yet.

See the generated component reference, event reference, and realtime protocol for exact fields and compatibility.

PixelRifts creator documentation · generated reference · protocol 21