TrapInteraction ​
Inherits: InteractableObjectInteraction < Interaction < Resource
Trap interaction - triggers effects through proximity, interaction, or events Integrates with combat system through effect application
Properties ​
int | trap_effect_id | -1 |
TriggerMode | trigger_mode | TriggerMode.PROXIMITY |
TriggerReusability | trigger_reusability | TriggerReusability.ONE_TIME |
float | cooldown_duration | 5.0 |
bool | visible_when_armed | true |
bool | trigger_players | true |
bool | trigger_npcs | true |
bool | trigger_pets | false |
bool | use_relationship_filter | false |
ReputationLevel.FactionRelationship | trigger_relationship | ReputationLevel.FactionRelationship.HOSTILE |
Vector3 | fixed_target_position | Vector3.ZERO |
bool | use_fixed_target | false |
Shape3D | detection_shape | |
Vector3 | detection_offset | Vector3.ZERO |
float | trigger_delay | 0.0 |
bool | repeat_timer_enabled | false |
float | repeat_timer_interval | 10.0 |
int | repeat_timer_count | -1 |
bool | lifetime_enabled | false |
float | lifetime_duration | 60.0 |
bool | cancel_persistent_effects | true |
SFXSelection | trigger_sound |
Variables ​
TrapState | current_trap_state | TrapState.ARMED |
Array[Entity] | entities_in_range | [] |
Timer | cooldown_timer | |
Timer | repeat_timer | |
Timer | lifetime_timer | |
int | current_repeat_count | 0 |
EffectInstance | active_effect_instance | |
Area3D | detection_area |
Methods ​
void | setup_for_interactable_objects( interactable: InteractableObject ) |
bool | can_interact( player: Player ) |
void | start_interaction( player: Player ) |
void | end_interaction() |
void | change_trap_state( new_state: TrapState ) |
bool | trigger_trap( target: Variant = null ) |
void | on_object_destroyed() |
void | reset_trap() |
void | disable_trap() |
bool | can_trigger() |
float | get_cooldown_remaining() |
float | get_lifetime_remaining() |
float | get_repeat_timer_remaining() |
bool | force_trigger( target: Variant = null ) |
void | extend_lifetime( additional_time: float ) |
Dictionary | save_state() |
void | load_state( state: Dictionary ) |
void | cleanup() |
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).