PhysicsWorld QML Type
Controls the physics simulation. More...
| Import Statement: | import QtQuick3D.Physics |
| Since: | Qt 6.4 |
Properties
- defaultDensity : real
- dynamicQueryStructure : QueryStructure
(since 6.13) - forceDebugDraw : bool
- gravity : vector3d
- maximumTimestep : real
- minimumTimestep : real
- numThreads : int
(since 6.7) - reportKinematicKinematicCollisions : bool
(since 6.7) - reportStaticKinematicCollisions : bool
(since 6.7) - running : bool
- scene : Node
- staticQueryStructure : QueryStructure
(since 6.13) - typicalLength : real
- typicalSpeed : real
- viewport : Node
Signals
- frameDone(float timestep)
(since 6.5)
Methods
- list<queryHit> multiOverlapQuery(CollisionShape shape, bool includeStatic, bool includeDynamic)
(since 6.13) - list<locationHit> multiRaycastQuery(vector3d origin, vector3d direction, real maxDistance, bool includeStatic, bool includeDynamic)
(since 6.13) - list<locationHit> multiSweepQuery(CollisionShape shape, vector3d direction, real maxDistance, bool includeStatic, bool includeDynamic)
(since 6.13) - locationHit singleRaycastQuery(vector3d origin, vector3d direction, real maxDistance, bool includeStatic, bool includeDynamic)
(since 6.13) - locationHit singleSweepQuery(CollisionShape shape, vector3d direction, real maxDistance, bool includeStatic, bool includeDynamic)
(since 6.13) - bool testOverlapQuery(CollisionShape shape, bool includeStatic, bool includeDynamic)
(since 6.13) - bool testRaycastQuery(vector3d origin, vector3d direction, real maxDistance, bool includeStatic, bool includeDynamic)
(since 6.13) - bool testSweepQuery(CollisionShape shape, vector3d direction, real maxDistance, bool includeStatic, bool includeDynamic)
(since 6.13)
Detailed Description
The PhysicsWorld type controls the physics simulation. This node is used to create an instance of the physics world as well as define its properties. There can only be one physics world. All collision nodes in the qml will get added automatically to the physics world.
Property Documentation
defaultDensity : real
This property defines the default density of dynamic objects, measured in kilograms per cubic unit. This is equal to the weight of a cube with side 1.
The default value is 0.001, corresponding to 1 g/cm³: the density of water. If your unit of measurement is meters, a good value would be 1000. Note that only positive values are allowed.
Range: (0, inf]
dynamicQueryStructure : QueryStructure [default: PhysicsWorld.DynamicTree, since 6.13]
The spatial pruning structure type used to accelerate scene queries (raycasts, sweeps, overlaps - used in CharacterController and a kinematic dynamic rigid body) against dynamic actors in the physics scene. It has no effect on rigid-body contact/collision detection during simulation.
The following values are available:
| Constant | Description |
|---|---|
PhysicsWorld.NoStructure | Disables the scene query acceleration structure for dynamic actors. Eliminates CPU overhead for tree maintenance when objects move, spawn, or are destroyed. Scene queries will fall back to a linear search. Ideal when scene queries are not needed for dynamic objects. |
PhysicsWorld.StaticTree | Uses a static AABB tree. Offers faster scene queries for dynamic actors, but updating the tree when objects move or spawn is very expensive. Best when dynamic actors rarely move or spend most of their time sleeping. |
PhysicsWorld.DynamicTree | Uses a dynamic self-balancing AABB tree. Allows fast, local runtime insertion (logarithmic time), movement, and removal of dynamic objects without freezing the frame. Ideal for active scenes with frequently moving or spawning dynamic actors. Note: Once the scene has started running it is not possible to change this setting. |
This property was introduced in Qt 6.13.
See also PhysicsWorld::staticQueryStructure.
forceDebugDraw : bool
This property enables debug drawing of all active shapes in the physics world. The default value is false.
gravity : vector3d
This property defines the gravity vector of the physics world. The default value is (0, -981, 0). Set the value to Qt.vector3d(0, -9.81, 0) if your unit of measurement is meters and you are simulating Earth gravity.
maximumTimestep : real
This property defines the maximum simulation timestep in milliseconds. The default value is 33.333.
Range: [0, inf]
Note: The simulation timestep works in lockstep with the rendering, meaning a new simulation frame will only be started after a rendered frame has completed. This means that at most one simulation frame will run per rendered frame.
minimumTimestep : real
This property defines the minimum simulation timestep in milliseconds. The default value is 1.
Range: [0, maximumTimestep]
Note: The simulation timestep works in lockstep with the rendering, meaning a new simulation frame will only be started after a rendered frame has completed. This means that at most one simulation frame will run per rendered frame.
numThreads : int [since 6.7]
This property defines the number of threads used for the physical simulation. This is how the range of values are interpreted:
| Value | Range | Description |
|---|---|---|
| Negative | [-inf, -1] | Automatic thread count. The application will try to query the number of threads from the system. |
| Zero | {0} | No threading, simulation will run sequentially. |
| Positive | [1, 256] | Specific thread count. Values above 256 are clamped. |
The default value is -1, meaning automatic thread count.
Note: Once the scene has started running it is not possible to change the number of threads.
This property was introduced in Qt 6.7.
reportKinematicKinematicCollisions : bool [since 6.7]
This property controls if collisions between pairs of kinematic dynamic rigid bodies will trigger a contact report.
The default value is false.
Note: Once the scene has started running it is not possible to change this setting.
This property was introduced in Qt 6.7.
See also PhysicsWorld::reportStaticKinematicCollisions, DynamicRigidBody, and PhysicsNode::bodyContact.
reportStaticKinematicCollisions : bool [since 6.7]
This property controls if collisions between a static rigid body and a kinematic dynamic rigid body will trigger a contact report.
The default value is false.
Note: Once the scene has started running it is not possible to change this setting.
This property was introduced in Qt 6.7.
See also PhysicsWorld::reportKinematicKinematicCollisions, StaticRigidBody, DynamicRigidBody, and PhysicsNode::bodyContact.
running : bool
This property starts or stops the physical simulation. The default value is true.
scene : Node
This property defines the top-most Node that contains all the nodes of the physical simulation. All physics objects that are an ancestor of this node will be seen as part of this PhysicsWorld.
Note: Using the same scene node for several PhysicsWorld is unsupported.
staticQueryStructure : QueryStructure [default: PhysicsWorld.DynamicTree, since 6.13]
The spatial pruning structure type used to accelerate scene queries (raycasts, sweeps, overlaps - used in CharacterController and a kinematic dynamic rigid body) against static actors in the physics scene. It has no effect on rigid-body contact/collision detection during simulation.
The following values are available:
| Constant | Description |
|---|---|
PhysicsWorld.StaticTree | Uses a pre-baked static AABB tree. Offers maximum scene query performance with zero per-frame management overhead. Best for fully static, immutable scenes. Inserting or removing objects at runtime causes heavy scene rebuilds and frame spikes. |
PhysicsWorld.DynamicTree | Uses a dynamic self-balancing AABB tree. Allows fast, local runtime insertion (logarithmic time) and removal of static objects without freezing the frame. Ideal for seamless open-world streaming where static chunks are loaded dynamically. Note: Once the scene has started running it is not possible to change this setting. Note: PhysicsWorld.NoStructure is not supported for staticQueryStructure |
This property was introduced in Qt 6.13.
See also PhysicsWorld::dynamicQueryStructure.
typicalLength : real
This property defines the approximate size of objects in the simulation. This is used to estimate certain length-related tolerances. Objects much smaller or much larger than this size may not behave properly. The default value is 100.
Range: [0, inf]
typicalSpeed : real
This property defines the typical magnitude of velocities of objects in simulation. This is used to estimate whether a contact should be treated as bouncing or resting based on its impact velocity, and a kinetic energy threshold below which the simulation may put objects to sleep.
For normal physical environments, a good choice is the approximate speed of an object falling under gravity for one second. The default value is 1000.
Range: [0, inf]
viewport : Node
This property defines the viewport where debug components will be drawn if forceDebugDraw is enabled. If unset the scene node will be used.
See also forceDebugDraw and scene.
Signal Documentation
[since 6.5] frameDone(float timestep)
This signal is emitted when the physical simulation is done simulating a frame. The timestep parameter is how long in milliseconds the timestep was in the simulation.
Note: The corresponding handler is onFrameDone.
This signal was introduced in Qt 6.5.
Method Documentation
[since 6.13] list<queryHit> multiOverlapQuery(CollisionShape shape, bool includeStatic = true, bool includeDynamic = true)
Returns every body that overlaps the volume of a stationary collision shape.
Returns a queryHit for each overlapping body, or an empty list if the volume is unoccupied.
- shape is the CollisionShape defining the overlap volume.
- includeStatic includes static bodies in the query when
true. - includeDynamic includes dynamic bodies in the query when
true.
The shape supplies the geometry of the query as well as its starting position and orientation: it is evaluated at its current scene transform, and any scaling on its node, including scaling inherited from parent nodes, is baked into the query geometry. Only BoxShape, SphereShape, CapsuleShape and ConvexMeshShape can be used; passing PlaneShape, TriangleMeshShape or HeightFieldShape produces no result and emits a warning.
At least one of includeStatic and includeDynamic must be true. If both are false the query does no work and reports no hit.
Trigger bodies, such as TriggerBody, are not colliders and are never reported. The filterGroup and filterIgnoreGroups properties affect simulation collisions only; scene queries ignore them.
Triangle mesh and heightfield shapes are reported once, at their closest intersection. The individual triangles of one mesh are not returned as separate hits.
Note: Hits are returned in spatial tree traversal order, not sorted by distance. Sort the list yourself if you need depth order.
This method was introduced in Qt 6.13.
See also testOverlapQuery and Qt Quick 3D Physics Scene Queries.
[since 6.13] list<locationHit> multiRaycastQuery(vector3d origin, vector3d direction, real maxDistance, bool includeStatic = true, bool includeDynamic = true)
Casts a ray through the physics scene and returns every body it passes through, rather than stopping at the closest one.
The ray starts at origin and extends along direction up to maxDistance. Returns a locationHit for each body hit, or an empty list if the ray hits nothing.
- origin is the starting position of the ray, in world space.
- direction is the direction of the ray. It must not be a null vector and does not need to be normalized; the query normalizes it.
- maxDistance is the maximum distance along direction to cast the ray. It must be greater than 0.
- includeStatic includes static bodies in the query when
true. - includeDynamic includes dynamic bodies in the query when
true.
At least one of includeStatic and includeDynamic must be true. If both are false the query does no work and reports no hit.
Trigger bodies, such as TriggerBody, are not colliders and are never reported. The filterGroup and filterIgnoreGroups properties affect simulation collisions only; scene queries ignore them.
A ray that starts inside a mesh, or that exits through a back-facing triangle, does not report that mesh.
Triangle mesh and heightfield shapes are reported once, at their closest intersection. The individual triangles of one mesh are not returned as separate hits.
Note: Hits are returned in spatial tree traversal order, not sorted by distance. Sort the list yourself if you need depth order.
This method was introduced in Qt 6.13.
See also testRaycastQuery, singleRaycastQuery, and Qt Quick 3D Physics Scene Queries.
[since 6.13] list<locationHit> multiSweepQuery(CollisionShape shape, vector3d direction, real maxDistance, bool includeStatic = true, bool includeDynamic = true)
Sweeps a collision shape along a straight path and returns every body it passes through, rather than stopping at the closest one.
Returns a locationHit for each body hit, or an empty list if the sweep hits nothing.
- shape is the CollisionShape to sweep through the scene.
- direction is the direction of the sweep. It must not be a null vector and does not need to be normalized; the query normalizes it.
- maxDistance is the maximum distance along direction to travel. It must be greater than 0.
- includeStatic includes static bodies in the query when
true. - includeDynamic includes dynamic bodies in the query when
true.
The shape supplies the geometry of the query as well as its starting position and orientation: it is evaluated at its current scene transform, and any scaling on its node, including scaling inherited from parent nodes, is baked into the query geometry. Only BoxShape, SphereShape, CapsuleShape and ConvexMeshShape can be used; passing PlaneShape, TriangleMeshShape or HeightFieldShape produces no result and emits a warning.
At least one of includeStatic and includeDynamic must be true. If both are false the query does no work and reports no hit.
Trigger bodies, such as TriggerBody, are not colliders and are never reported. The filterGroup and filterIgnoreGroups properties affect simulation collisions only; scene queries ignore them.
Triangle mesh and heightfield shapes are reported once, at their closest intersection. The individual triangles of one mesh are not returned as separate hits.
Note: Hits are returned in spatial tree traversal order, not sorted by distance. Sort the list yourself if you need depth order.
Note: If shape already overlaps a body at its starting position, that hit reports a negative distance whose magnitude is the penetration depth, along with the position and normal needed to separate the two shapes.
This method was introduced in Qt 6.13.
See also testSweepQuery, singleSweepQuery, and Qt Quick 3D Physics Scene Queries.
[since 6.13] locationHit singleRaycastQuery(vector3d origin, vector3d direction, real maxDistance, bool includeStatic = true, bool includeDynamic = true)
Casts a ray through the physics scene and returns the closest body it hits.
The ray starts at origin and extends along direction up to maxDistance. Returns a locationHit describing the closest intersection.
- origin is the starting position of the ray, in world space.
- direction is the direction of the ray. It must not be a null vector and does not need to be normalized; the query normalizes it.
- maxDistance is the maximum distance along direction to cast the ray. It must be greater than 0.
- includeStatic includes static bodies in the query when
true. - includeDynamic includes dynamic bodies in the query when
true.
At least one of includeStatic and includeDynamic must be true. If both are false the query does no work and reports no hit.
If nothing is hit, or the arguments are invalid, the returned hit has a null body. Every body in the scene has an associated node, so hit.body === null is the reliable test for a miss; the distance of a missed hit is 0 and carries no meaning.
Trigger bodies, such as TriggerBody, are not colliders and are never reported. The filterGroup and filterIgnoreGroups properties affect simulation collisions only; scene queries ignore them.
A ray that starts inside a mesh, or that exits through a back-facing triangle, does not report that mesh.
This method was introduced in Qt 6.13.
See also testRaycastQuery, multiRaycastQuery, and Qt Quick 3D Physics Scene Queries.
[since 6.13] locationHit singleSweepQuery(CollisionShape shape, vector3d direction, real maxDistance, bool includeStatic = true, bool includeDynamic = true)
Sweeps a collision shape along a straight path and returns the closest body it hits.
Returns a locationHit describing the closest intersection encountered along the sweep.
- shape is the CollisionShape to sweep through the scene.
- direction is the direction of the sweep. It must not be a null vector and does not need to be normalized; the query normalizes it.
- maxDistance is the maximum distance along direction to travel. It must be greater than 0.
- includeStatic includes static bodies in the query when
true. - includeDynamic includes dynamic bodies in the query when
true.
The shape supplies the geometry of the query as well as its starting position and orientation: it is evaluated at its current scene transform, and any scaling on its node, including scaling inherited from parent nodes, is baked into the query geometry. Only BoxShape, SphereShape, CapsuleShape and ConvexMeshShape can be used; passing PlaneShape, TriangleMeshShape or HeightFieldShape produces no result and emits a warning.
At least one of includeStatic and includeDynamic must be true. If both are false the query does no work and reports no hit.
If nothing is hit, or the arguments are invalid, the returned hit has a null body. Every body in the scene has an associated node, so hit.body === null is the reliable test for a miss; the distance of a missed hit is 0 and carries no meaning.
Trigger bodies, such as TriggerBody, are not colliders and are never reported. The filterGroup and filterIgnoreGroups properties affect simulation collisions only; scene queries ignore them.
Note: If shape already overlaps a body at its starting position, that hit reports a negative distance whose magnitude is the penetration depth, along with the position and normal needed to separate the two shapes.
This method was introduced in Qt 6.13.
See also testSweepQuery, multiSweepQuery, and Qt Quick 3D Physics Scene Queries.
[since 6.13] bool testOverlapQuery(CollisionShape shape, bool includeStatic = true, bool includeDynamic = true)
Reports whether any body occupies the volume of a stationary collision shape.
Returns true if shape overlaps a body; otherwise returns false. The query stops at the first body it finds and builds no hit data, which makes it the cheapest of the overlap queries.
- shape is the CollisionShape defining the overlap volume.
- includeStatic includes static bodies in the query when
true. - includeDynamic includes dynamic bodies in the query when
true.
The shape supplies the geometry of the query as well as its starting position and orientation: it is evaluated at its current scene transform, and any scaling on its node, including scaling inherited from parent nodes, is baked into the query geometry. Only BoxShape, SphereShape, CapsuleShape and ConvexMeshShape can be used; passing PlaneShape, TriangleMeshShape or HeightFieldShape produces no result and emits a warning.
At least one of includeStatic and includeDynamic must be true. If both are false the query does no work and reports no hit.
Trigger bodies, such as TriggerBody, are not colliders and are never reported. The filterGroup and filterIgnoreGroups properties affect simulation collisions only; scene queries ignore them.
This method was introduced in Qt 6.13.
See also multiOverlapQuery and Qt Quick 3D Physics Scene Queries.
[since 6.13] bool testRaycastQuery(vector3d origin, vector3d direction, real maxDistance, bool includeStatic = true, bool includeDynamic = true)
Performs a fast occlusion check along a ray without computing precise hit geometry or returning hit data.
Returns true if the ray hits a body within maxDistance; otherwise returns false. The query stops at the first body it finds, which makes it the cheapest of the raycast queries.
- origin is the starting position of the ray, in world space.
- direction is the direction of the ray. It must not be a null vector and does not need to be normalized; the query normalizes it.
- maxDistance is the maximum distance along direction to cast the ray. It must be greater than 0.
- includeStatic includes static bodies in the query when
true. - includeDynamic includes dynamic bodies in the query when
true.
At least one of includeStatic and includeDynamic must be true. If both are false the query does no work and reports no hit.
Trigger bodies, such as TriggerBody, are not colliders and are never reported. The filterGroup and filterIgnoreGroups properties affect simulation collisions only; scene queries ignore them.
A ray that starts inside a mesh, or that exits through a back-facing triangle, does not report that mesh.
This method was introduced in Qt 6.13.
See also singleRaycastQuery, multiRaycastQuery, and Qt Quick 3D Physics Scene Queries.
[since 6.13] bool testSweepQuery(CollisionShape shape, vector3d direction, real maxDistance, bool includeStatic = true, bool includeDynamic = true)
Sweeps a collision shape along a straight path and reports whether the path is obstructed, without computing precise hit geometry.
Returns true if shape hits a body before travelling maxDistance; otherwise returns false. The query stops at the first body it finds, which makes it the cheapest of the sweep queries.
- shape is the CollisionShape to sweep through the scene.
- direction is the direction of the sweep. It must not be a null vector and does not need to be normalized; the query normalizes it.
- maxDistance is the maximum distance along direction to travel. It must be greater than 0.
- includeStatic includes static bodies in the query when
true. - includeDynamic includes dynamic bodies in the query when
true.
The shape supplies the geometry of the query as well as its starting position and orientation: it is evaluated at its current scene transform, and any scaling on its node, including scaling inherited from parent nodes, is baked into the query geometry. Only BoxShape, SphereShape, CapsuleShape and ConvexMeshShape can be used; passing PlaneShape, TriangleMeshShape or HeightFieldShape produces no result and emits a warning.
At least one of includeStatic and includeDynamic must be true. If both are false the query does no work and reports no hit.
Trigger bodies, such as TriggerBody, are not colliders and are never reported. The filterGroup and filterIgnoreGroups properties affect simulation collisions only; scene queries ignore them.
This method was introduced in Qt 6.13.
See also singleSweepQuery, multiSweepQuery, and Qt Quick 3D Physics Scene Queries.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.