PhysicsWorld accessible via Scene.PhysicsWorld. You create dynamic objects by attaching a Rigidbody component alongside one or more collider components. For spatial queries you use the fluent trace builder returned by Scene.PhysicsWorld.Trace.
Physics traces
A trace (or raycast) sweeps a shape through the physics world and returns everything it hits. The builder pattern lets you compose exactly the query you need.Ray trace
The simplest trace casts an infinitely thin ray from one point to another:Sphere sweep
Box sweep
Capsule sweep
RunAll — multiple hits
Filtering the trace
Chain filter methods before callingRun():
| Method | Effect |
|---|---|
IgnoreStatic() | Exclude static bodies |
IgnoreDynamic() | Exclude dynamic bodies |
IgnoreKeyframed() | Exclude keyframed bodies |
HitTriggers() | Include trigger shapes in results |
HitTriggersOnly() | Hit only trigger shapes |
PhysicsTraceResult fields
| Field | Type | Description |
|---|---|---|
Hit | bool | Whether the trace hit anything |
StartedSolid | bool | The trace started inside a solid |
HitPosition | Vector3 | World position of the hit |
EndPosition | Vector3 | Final position after travel |
Normal | Vector3 | Surface normal at the hit point |
Fraction | float | How far [0..1] the trace travelled |
Body | PhysicsBody | The physics body that was hit |
Shape | PhysicsShape | The specific shape that was hit |
Surface | Surface | Material/surface properties |
Tags | string[] | Tags on the hit shape |
Distance | float | Distance between start and end |
Rigidbody component
Add aRigidbody component to give a GameObject physics simulation. It requires at least one collider component (e.g. BoxCollider, SphereCollider, CapsuleCollider) on the same or a child GameObject.
Velocity and forces
Mass and damping
Sleeping
Physics bodies automatically sleep after being still to save performance:Accessing the underlying PhysicsBody
PhysicsBody API
You can also work withPhysicsBody directly for lower-level control:
Collision detection
ImplementICollisionListener on a component to receive collision callbacks:
Shape management
Shapes define the collision geometry of aPhysicsBody. You can add shapes at runtime: