Physics Engine
Configure Rapier physics with rigid bodies, colliders, and PLC interaction
Physics Engine
Sim Assist uses the Rapier physics engine to simulate rigid body dynamics, collisions, and constraints. Physics simulation runs in sync with the PLC execution cycle, allowing your control logic to interact with physically accurate objects.
Overview
Rapier is a high-performance physics engine written in Rust and compiled to WebAssembly for browser execution. It handles:
- Rigid body dynamics (gravity, forces, impulses, velocity)
- Collision detection and response
- Joints and constraints (revolute, prismatic, fixed)
- Continuous collision detection (CCD) for fast-moving objects
Physics are configured per component. Not every component needs physics — static scenery like floors, walls, and decorative elements can remain as purely visual objects.
Rigid Body Types
Each physics-enabled component has a rigid body that defines how it behaves in the simulation:
Dynamic
Dynamic bodies are fully simulated. They respond to gravity, collisions, forces, and impulses. Use dynamic bodies for objects that should fall, slide, tumble, or be pushed — such as boxes on a conveyor, parts being sorted, or products being palletized.
Static
Static bodies never move. They act as immovable obstacles for dynamic bodies to collide with. Use static bodies for floors, walls, machine frames, and fixed structures. Static bodies have zero computational cost for the physics solver.
Kinematic
Kinematic bodies are moved by your PLC program rather than by the physics engine. They are not affected by gravity or collisions, but other dynamic bodies can collide with them. Use kinematic bodies for actuators, conveyor belts, robot arms, and any component whose position or velocity is controlled by PLC output variables.
To set a rigid body type, select the component, open the Physics section in the Properties panel, and choose the type from the dropdown.
Collider Shapes
Colliders define the physical shape used for collision detection. They do not need to match the visual mesh exactly — simpler collider shapes are faster to compute.
| Shape | Use Case | Performance |
|---|---|---|
| Box | Crates, pallets, machine housings | Fastest |
| Sphere | Balls, round objects, approximate shapes | Fastest |
| Capsule | Cylindrical objects, bottles, rollers | Fast |
| Convex Hull | Irregular but convex shapes | Moderate |
| Triangle Mesh | Concave or highly detailed shapes | Slowest |
Recommendation: Use box and sphere colliders whenever possible. Reserve triangle mesh colliders for static geometry where precise collision boundaries matter (e.g., complex machine frames). Dynamic bodies with mesh colliders are expensive and should be avoided.
To add a collider, select the component, go to the Physics section, and click Add Collider. Choose the shape type and adjust the size, offset, and rotation to fit the visual mesh. You can add multiple colliders to a single component to approximate complex shapes.
PLC Interaction with Physics
The real power of Sim Assist emerges when physics and PLC logic work together. Here are common patterns:
Position Sensors
Attach a sensor zone (trigger collider) to a component. When a dynamic body enters the zone, the bound input variable becomes TRUE. Your PLC program reads this to detect part presence, count items, or trigger sequences.
Actuators (Kinematic Control)
Set a component's rigid body to Kinematic. Bind its velocity or target position to a PLC output variable. Your PLC program controls the actuator by setting speed values or position targets. Examples include conveyor belt speed, cylinder extension, and rotary table angle.
Force-Based Control
For dynamic bodies that need to be influenced rather than directly positioned, apply forces or impulses through PLC output variables. This is useful for simulating pneumatic pushers, blowers, or gravity-fed systems where the physics engine should determine the resulting motion.
Reading Physical State
Bind input variables to a dynamic body's position, rotation, or velocity. Your PLC program can read the actual position of a falling part, the angle of a hinged door, or the speed of a rolling object.
Joints and Constraints
Joints connect two rigid bodies and restrict their relative motion:
- Revolute Joint — Allows rotation around a single axis. Used for hinges, wheels, and rotating platforms.
- Prismatic Joint — Allows translation along a single axis. Used for linear actuators, slides, and pistons.
- Fixed Joint — Locks two bodies together with no relative motion. Used for creating rigid assemblies from multiple parts.
Configure joints in the Physics section of the Properties panel by clicking Add Joint and selecting the connected body and joint type.
Performance Considerations
Physics simulation runs every scan cycle (default 20ms). To maintain real-time performance:
- Limit dynamic bodies — Each dynamic body adds to the solver workload. Aim for under 200 active dynamic bodies in a scene.
- Use simple colliders — Prefer boxes and spheres over mesh colliders. A stack of 50 boxes with box colliders runs much faster than 50 boxes with mesh colliders.
- Freeze distant objects — Use the
sleepingproperty to deactivate bodies that are stationary. Rapier handles this automatically by default, but you can force sleep on bodies that are not relevant to the current simulation state. - Adjust solver iterations — In project settings, you can increase solver iterations for more accurate stacking and joint behavior, or decrease them for better performance. The default of 4 velocity iterations and 1 position iteration works well for most industrial simulations.
- Use CCD selectively — Continuous collision detection prevents fast objects from passing through thin walls, but it is more expensive. Enable it only on components that move quickly, such as ejected parts or fast conveyor items.