Respawn an actor on death
Problem. You want a defeated actor to come back after a short delay instead of being gone for good.
Pattern. Watch the actor's health resource with a condition, and when it hits zero run
an action chain that restores the resource and moves the actor back to a spawn point. A
Timer entity introduces the delay before the restore runs.
The building blocks are all data entities:
- a
Resource(health) with aminof0, - an
Actionthat setshealthback to full and teleports the actor to aVectorspawn point, - a
Trigger(or aStrategycondition) that fires the action whenhealthreaches0, - a
Timerto delay the respawn.
Action:
respawnHero:
do: set_resource_self
parameters: [respawnResource, respawnValue]
then: respawnMove
respawnMove:
do: set_destination_self
parameters: [respawnPoint]
Parameter:
respawnResource: {key: resource, value: health}
respawnValue: {key: value, value: "100"}
respawnPoint: {key: destination, value: heroSpawn}
Vector:
heroSpawn: {x: 240, y: 160}
See the action reference for the exact parameters of
set_resource_self and set_destination_self, and the
entity reference for Trigger, Timer, and Resource fields.