Overview
The Event System allows particles to respond dynamically to physical conditions by triggering actions when specific criteria are met. Events are perfect for:- Pausing the simulation at critical moments (collisions, boundaries, etc.)
- Changing particle appearance based on state
- Creating complex conditional behaviors
- Debugging and analyzing particle motion
Event Structure
Each event consists of three main components:Movimiento.ts
Event Conditions
Conditions determine when an event should trigger.Condition Structure
EventCondition
Available Variables
You can create conditions based on these particle properties:| Variable | Description | Example Use Case |
|---|---|---|
x | Position on X-axis | Detect boundary crossing |
y | Position on Y-axis | Detect boundary crossing |
z | Position on Z-axis (height) | Detect ground collision |
t | Elapsed time | Time-based triggers |
vx | Velocity in X direction | Detect stopping/acceleration |
vy | Velocity in Y direction | Detect stopping/acceleration |
vz | Velocity in Z direction | Detect peak height (vz=0) |
v | Speed (magnitude of velocity) | Detect threshold speeds |
The
v variable is computed as: v = sqrt(vx² + vy² + vz²)Comparison Operators
| Operator | Meaning | Example Condition |
|---|---|---|
== | Equals (with tolerance) | z == 0 (touching ground) |
!= | Not equals | vz != 0 (still moving vertically) |
> | Greater than | z > 10 (above 10 meters) |
< | Less than | v < 0.1 (nearly stopped) |
>= | Greater than or equal | t >= 5 (after 5 seconds) |
<= | Less than or equal | z <= 0 (at or below ground) |
The
== operator uses a tolerance of 0.01 for floating-point comparison. Use <= or >= for more reliable boundary detection.Tolerance Implementation
PhysicsUpdate.tsx
Condition Logic
When an event has multiple conditions, you can choose how they combine:AND Logic
ALL conditions must be true for the event to trigger. Example: Detect particle stopped on groundConditions (AND)
OR Logic
ANY condition being true will trigger the event. Example: Detect particle leaving bounded areaConditions (OR)
Switching Logic Mode
Condition Logic Selector
Event Actions
Actions define what happens when an event triggers.Action Types
EventAction
Pause Action
Stops the simulation immediately:Pause Action
- Stop at ground collision
- Pause at maximum height
- Stop when particle exits bounds
- Debug specific states
Change Color Action
Changes the particle’s color:Change Color Action
- Visual feedback for state changes
- Indicate threshold crossings
- Mark collision events
- Show particle groups
Action Execution
PhysicsUpdate.tsx
Multiple actions can be added to a single event. They execute sequentially when the event triggers.
Event Lifecycle
Event States
- Enabled: Event actively checks conditions every frame
- Disabled: Event exists but conditions are not evaluated
- Triggered: Event has fired and won’t trigger again until reset
Trigger Prevention
Events only trigger once per simulation run:Event Evaluation
Resetting Events
Events reset when you:- Click the RESET button
- Edit the particle properties
- Reload a configuration
Escenario.tsx
Creating Events
Adding a New Event
- Open the particle editor
- Scroll to the Events section
- Click ”+ ADD EVENT”
Add Event
Editing Event Name
Click the event name field to edit:Event Name
Toggling Event State
Click the ON/OFF button:- Green (ON): Event is enabled
- Gray (OFF): Event is disabled
Managing Conditions
Adding Conditions
Click ”+ Condition” within an event:Add Condition
Editing Conditions
Each condition has three dropdowns/inputs:Condition Editor
Removing Conditions
Click the ”-” button next to a condition to remove it.Managing Actions
Adding Actions
Click ”+ Action” within an event:Add Action
Editing Actions
Select action type:Action Type Selector
Color Picker for Action
Removing Actions
Click the ”-” button next to an action to remove it.Real Examples
Example 1: Ground Collision Detection
Goal: Pause simulation when projectile hits the groundEvent Configuration
Example 2: Peak Height Detection
Goal: Change color when projectile reaches maximum height (vz = 0)Event Configuration
Example 3: Speed Threshold Alert
Goal: Turn red when particle exceeds speed limitEvent Configuration
Example 4: Boundary Escape Detection
Goal: Pause if particle leaves the bounded regionEvent Configuration
Example 5: Time-Based State Change
Goal: Change color after 10 secondsEvent Configuration
Example 6: Stopped Particle Detection
Goal: Detect when particle comes to restEvent Configuration
Event Visual Indicators
The editor provides visual feedback for event states:Background Colors
- Normal:
rgba(255,255,255,0.05)- Not triggered - Triggered:
rgba(40, 167, 69, 0.2)- Green tint
Border Colors
- Enabled: Yellow border
rgba(255,193,7,0.5) - Disabled: Gray border
rgba(100,100,100,0.3)
Status Badge
Triggered Badge
Best Practices
Use meaningful event names
Use meaningful event names
Name events descriptively:
- ✅ “Ground Collision”
- ✅ “Max Height Reached”
- ❌ “Event 1”
- ❌ “Test”
Account for floating-point precision
Account for floating-point precision
Use
<= or >= instead of == for critical values:Better
Risky
Combine actions for rich feedback
Combine actions for rich feedback
Multiple actions provide better visualization:This both marks the event visually AND stops for inspection.
Good Event
Use OR logic for boundaries
Use OR logic for boundaries
When checking multiple boundaries, OR logic is more appropriate:Using AND would require all to be true simultaneously (impossible).
Correct (OR)
Disable events for testing
Disable events for testing
Disable events temporarily rather than deleting them:
- Click ON/OFF button to toggle
- Preserves event configuration
- Easy to re-enable later
Troubleshooting
Event Never Triggers
Check:- Is the event enabled (green ON button)?
- Are conditions physically possible?
- Is the tolerance too strict for
==comparisons? - For AND logic, can all conditions be true simultaneously?
Event Triggers Immediately
Possible causes:- Initial conditions already satisfy the event
- Check z <= 0 with particles starting at ground level
- Verify time conditions (t >= 0 always triggers immediately)
Event Triggers Multiple Times
Events should only trigger once. If this happens:- Check if the event was properly reset
- Verify the
triggeredflag is being set - This is likely a bug - events are designed to fire once
Color Change Not Visible
- Ensure the action has a
payloadwith a valid hex color - Check if another event is overriding the color
- Verify the particle is visible (not off-screen)
Advanced Patterns
Chaining Events with Color States
Use multiple events with color changes to track state progression:Event 1: Launch Phase
Composite Detection
Combine position and velocity for precise detection:Event: Landing with High Speed
Related Topics
Formula Syntax
Understand variables used in conditions (x, y, z, vx, vy, vz, v, t)
Particle Editor
Learn how to access and manage the events interface