Skip to content

TrapInteraction ​

Inherits: InteractableObjectInteraction < Interaction < Resource

Trap interaction - triggers effects through proximity, interaction, or events Integrates with combat system through effect application

Properties ​

inttrap_effect_id-1
TriggerModetrigger_modeTriggerMode.PROXIMITY
TriggerReusabilitytrigger_reusabilityTriggerReusability.ONE_TIME
floatcooldown_duration5.0
boolvisible_when_armedtrue
booltrigger_playerstrue
booltrigger_npcstrue
booltrigger_petsfalse
booluse_relationship_filterfalse
ReputationLevel.FactionRelationshiptrigger_relationshipReputationLevel.FactionRelationship.HOSTILE
Vector3fixed_target_positionVector3.ZERO
booluse_fixed_targetfalse
Shape3Ddetection_shape
Vector3detection_offsetVector3.ZERO
floattrigger_delay0.0
boolrepeat_timer_enabledfalse
floatrepeat_timer_interval10.0
intrepeat_timer_count-1
boollifetime_enabledfalse
floatlifetime_duration60.0
boolcancel_persistent_effectstrue
SFXSelectiontrigger_sound

Variables ​

TrapStatecurrent_trap_stateTrapState.ARMED
Array[Entity]entities_in_range[]
Timercooldown_timer
Timerrepeat_timer
Timerlifetime_timer
intcurrent_repeat_count0
EffectInstanceactive_effect_instance
Area3Ddetection_area

Methods ​

voidsetup_for_interactable_objects( interactable: InteractableObject )
boolcan_interact( player: Player )
voidstart_interaction( player: Player )
voidend_interaction()
voidchange_trap_state( new_state: TrapState )
booltrigger_trap( target: Variant = null )
voidon_object_destroyed()
voidreset_trap()
voiddisable_trap()
boolcan_trigger()
floatget_cooldown_remaining()
floatget_lifetime_remaining()
floatget_repeat_timer_remaining()
boolforce_trigger( target: Variant = null )
voidextend_lifetime( additional_time: float )
Dictionarysave_state()
voidload_state( state: Dictionary )
voidcleanup()

Signals ​

trap_triggered( target: Variant, effect_instance: EffectInstance, triggering_entity: Entity ) ​

Emitted when the trap fires: the target, the effect and who triggered it.

trap_activated( triggering_entity: Entity ) ​

Emitted when something sets the trap off.

trap_state_changed( old_state: TrapState, new_state: TrapState ) ​

Emitted when the state of the trap changes.

trap_lifetime_expired() ​

Emitted when the lifetime of the trap ends.

Enumerations ​

enum TriggerMode ​

What sets the trap off: something that comes near (proximity), someone who uses it (interaction) or only an event.

  • PROXIMITY = 0
  • INTERACTION = 1

enum TriggerReusability ​

How often the trap fires: once, again after a cooldown, or every time with no cooldown.

  • ONE_TIME = 0
  • COOLDOWN = 1
  • cooldown = 2

enum TrapState ​

The states of a trap: armed, triggered, in cooldown, disabled or destroyed.

  • ARMED = 0
  • TRIGGERED = 1
  • COOLDOWN = 2
  • DISABLED = 3

Property descriptions ​

Trap Configuration

int trap_effect_id = -1 ​

The effect ID to apply when triggered (from Database)

TriggerMode trigger_mode = TriggerMode.PROXIMITY ​

What sets the trap off.

TriggerReusability trigger_reusability = TriggerReusability.ONE_TIME ​

How often the trap can fire.

float cooldown_duration = 5.0 ​

Only used if reusability is COOLDOWN

bool visible_when_armed = true ​

Whether trap is visible when armed

Trigger Targeting

bool trigger_players = true ​

Can trigger on player characters

bool trigger_npcs = true ​

Can trigger on NPCs

bool trigger_pets = false ​

Can trigger on player pets

bool use_relationship_filter = false ​

Also ask how the faction of the trap relates to the one that walks in (a placed trap is environmental, neutral to all, so this is off by default: the type options decide). A trap that was summoned always asks: it only hurts the enemies of its summoner

ReputationLevel.FactionRelationship trigger_relationship = ReputationLevel.FactionRelationship.HOSTILE ​

The relation to the faction of the trap that sets it off (hostile by default). Only used when the relationship filter is on.

Targeting

Vector3 fixed_target_position = Vector3.ZERO ​

Fixed position to always target (instead of triggering entity)

bool use_fixed_target = false ​

Whether to use the fixed target position

Proximity Settings

Shape3D detection_shape ​

Shape for the detection area (SphereShape3D, BoxShape3D, etc.)

Vector3 detection_offset = Vector3.ZERO ​

Offset from trap position for detection area

float trigger_delay = 0.0 ​

Delay before triggering after detection

Timer Settings

bool repeat_timer_enabled = false ​

Whether trap repeats on a timer

float repeat_timer_interval = 10.0 ​

Time between repeat triggers

int repeat_timer_count = -1 ​

Number of repeats (-1 = infinite)

Lifetime Settings

bool lifetime_enabled = false ​

Whether trap has a limited lifetime

float lifetime_duration = 60.0 ​

How long trap remains active

bool cancel_persistent_effects = true ​

Cancel persistent effects when lifetime expires

Audio

SFXSelection trigger_sound ​

The sound the trap makes when it fires.

Variable descriptions ​

TrapState current_trap_state = TrapState.ARMED ​

The state of the trap now.

Array[Entity] entities_in_range = [] ​

The entities inside the detection area of the trap.

Timer cooldown_timer ​

The timer of the cooldown between two triggers.

Timer repeat_timer ​

The timer between repeats of the effect.

Timer lifetime_timer ​

The timer that ends the trap when its lifetime is over.

int current_repeat_count = 0 ​

How many times the effect has repeated in this trigger.

EffectInstance active_effect_instance ​

The effect the trap has put on a target and keeps running.

Area3D detection_area ​

Detection area created at runtime

Method descriptions ​

void setup_for_interactable_objects( interactable: InteractableObject ) ​

Sets the trap up on its object: finds the nodes it needs and applies its starting state.

bool can_interact( player: Player ) ​

Can the player use the trap now (in range, the object is not broken, the requirements are met)?

void start_interaction( player: Player ) ​

The player uses the trap.

void end_interaction() ​

Does nothing: a trap has no end of interaction.

void change_trap_state( new_state: TrapState ) ​

Puts the trap in a state (armed, triggered, cooldown ...).

bool trigger_trap( target: Variant = null ) ​

Main trigger method - can be called externally

void on_object_destroyed() ​

Called when the object is destroyed: the trap goes to its destroyed state.

void reset_trap() ​

Reset trap to armed state

void disable_trap() ​

Disable trap permanently

bool can_trigger() ​

Check if trap can currently trigger

float get_cooldown_remaining() ​

Get remaining cooldown time

float get_lifetime_remaining() ​

Get remaining lifetime

float get_repeat_timer_remaining() ​

Get remaining repeat timer time

bool force_trigger( target: Variant = null ) ​

Force trigger regardless of conditions (for event system)

void extend_lifetime( additional_time: float ) ​

Extend trap lifetime

Dictionary save_state() ​

The state of the trap for a save.

void load_state( state: Dictionary ) ​

Restores the state of the trap from a save.

void cleanup() ​

Gives its timers back and clears what it holds (the object is going away).