A component that defines an entity’s behavior in physics body simulations.
Only entities with a ``RealityKit/PhysicsBodyComponent``
and a ``RealityKit/CollisionComponent``
can participate in a scene's physics simulation.
If you need to move an entity that participates
in the physics system, it also needs a ``RealityKit/PhysicsMotionComponent``.
Add a physics body component to an entity by adopting the ``HasPhysicsBody`` protocol, which
allows RealityKit’s physics simulation to compute behavior in response to forces acting upon the body,
following basic rules of Newtonian mechanics.
Note the following when considering applying a non-uniform scale to an entity:
- Non-uniform scaling is applicable only to box, convex mesh and triangle mesh collision shapes.
- Non-uniform scaling is not supported for all other types of collision shapes. In this case the scale.x
value is duplicated to the scale's y and z components as well to force scale uniformity based on the x component.
- If the entity has a non-uniform scale assigned to its transform then that entity should not
have any descendants assigned that contain rotations in their transforms. A good rule of thumb is to
assign the non-uniform scale to the entity that has the collision shape, and avoid adding children below
that entity.
- Note: Model entities have a physics body component by default.
Members (22)
get · iOS 18.0+
linearDamping
TypeScript
get linearDamping(): number
Swift declaration
var linearDamping: Float { get set }
The value that controls how fast a dynamic rigid body's translation motion approaches the zero rest state.
- Important: Use a non-negative value for linear damping.
set · iOS 18.0+
linearDamping
TypeScript
set linearDamping(value: number)
Swift declaration
var linearDamping: Float { get set }
The value that controls how fast a dynamic rigid body's translation motion approaches the zero rest state.
- Important: Use a non-negative value for linear damping.
get · iOS 18.0+
angularDamping
TypeScript
get angularDamping(): number
Swift declaration
var angularDamping: Float { get set }
The value that controls how fast a dynamic rigid body's rotational motion approaches the zero rest state.
- Important: Use a non-negative value for angular damping.
set · iOS 18.0+
angularDamping
TypeScript
set angularDamping(value: number)
Swift declaration
var angularDamping: Float { get set }
The value that controls how fast a dynamic rigid body's rotational motion approaches the zero rest state.
- Important: Use a non-negative value for angular damping.
Creates a physics body component with the given mass properties,
material, and mode.
- Parameters:
- massProperties: The mass properties, like inertia.
- material: The material properties, like friction.
- mode: The simulation mode that indicates how a body responds to
forces.
get · iOS 13.0+
massProperties
TypeScript
get massProperties(): PhysicsMassProperties
Swift declaration
var massProperties: PhysicsMassProperties
The physics body’s mass properties, like inertia and center of mass.
By default, the mass properties value is
``PhysicsMassProperties/default``, which matches the properties of a
unit sphere with mass of 1 kilogram.
set · iOS 13.0+
massProperties
TypeScript
set massProperties(value: PhysicsMassProperties)
Swift declaration
var massProperties: PhysicsMassProperties
The physics body’s mass properties, like inertia and center of mass.
By default, the mass properties value is
``PhysicsMassProperties/default``, which matches the properties of a
unit sphere with mass of 1 kilogram.
get · iOS 13.0+
isRotationLocked
TypeScript
get isRotationLocked(): { "x": boolean; "y": boolean; "z": boolean }
Swift declaration
var isRotationLocked: (x: Bool, y: Bool, z: Bool)
A tuple of Boolean values that you use to lock rotation of the physics
body around any of the three axes.
For any one of the three Booleans in the tuple that you set to `true`,
rotation is restricted on the axis represented by that item. For
example, if you set the `x` item to true, then the body can’t rotate
around the x-axis. By default, rotation isn’t restricted.
set · iOS 13.0+
isRotationLocked
TypeScript
set isRotationLocked(value: { "x": boolean; "y": boolean; "z": boolean })
Swift declaration
var isRotationLocked: (x: Bool, y: Bool, z: Bool)
A tuple of Boolean values that you use to lock rotation of the physics
body around any of the three axes.
For any one of the three Booleans in the tuple that you set to `true`,
rotation is restricted on the axis represented by that item. For
example, if you set the `x` item to true, then the body can’t rotate
around the x-axis. By default, rotation isn’t restricted.
get · iOS 18.0+
isAffectedByGravity
TypeScript
get isAffectedByGravity(): boolean
Swift declaration
var isAffectedByGravity: Bool { get set }
A Boolean value that indicates whether gravity acts on dynamic rigid bodies.
set · iOS 18.0+
isAffectedByGravity
TypeScript
set isAffectedByGravity(value: boolean)
Swift declaration
var isAffectedByGravity: Bool { get set }
A Boolean value that indicates whether gravity acts on dynamic rigid bodies.
get · iOS 13.0+
isTranslationLocked
TypeScript
get isTranslationLocked(): { "x": boolean; "y": boolean; "z": boolean }
Swift declaration
var isTranslationLocked: (x: Bool, y: Bool, z: Bool)
A tuple of Boolean values that you use to lock the position of the
physics body along any of the three axes.
You can restrict movement of the body along one or more axes by setting
the corresponding item in the tuple to `true`. For example, if you set
the `x` and the `z` items in the tuple to `true`, then the body can move
only along the y-axis. By default, movement isn’t restricted.
set · iOS 13.0+
isTranslationLocked
TypeScript
set isTranslationLocked(value: { "x": boolean; "y": boolean; "z": boolean })
Swift declaration
var isTranslationLocked: (x: Bool, y: Bool, z: Bool)
A tuple of Boolean values that you use to lock the position of the
physics body along any of the three axes.
You can restrict movement of the body along one or more axes by setting
the corresponding item in the tuple to `true`. For example, if you set
the `x` and the `z` items in the tuple to `true`, then the body can move
only along the y-axis. By default, movement isn’t restricted.
get · iOS 13.0+
isContinuousCollisionDetectionEnabled
TypeScript
get isContinuousCollisionDetectionEnabled(): boolean
Swift declaration
var isContinuousCollisionDetectionEnabled: Bool
A Boolean that controls whether the physics simulation performs
continuous collision detection.
Set the value to `true` to perform continuous collision detection. The
value is `false` by default, indicating the simulation should apply
discrete collision detection.
Discrete collision detection considers only the position of a body once
per rendered frame, or about every 16 milliseconds at 60 frames per
second. Continuous collision detection considers the position of the
body throughout the frame interval. The latter is more computationally
expensive, but can help to avoid missing a collision for a quickly
moving object, like a projectile.
set · iOS 13.0+
isContinuousCollisionDetectionEnabled
TypeScript
set isContinuousCollisionDetectionEnabled(value: boolean)
Swift declaration
var isContinuousCollisionDetectionEnabled: Bool
A Boolean that controls whether the physics simulation performs
continuous collision detection.
Set the value to `true` to perform continuous collision detection. The
value is `false` by default, indicating the simulation should apply
discrete collision detection.
Discrete collision detection considers only the position of a body once
per rendered frame, or about every 16 milliseconds at 60 frames per
second. Continuous collision detection considers the position of the
body throughout the frame interval. The latter is more computationally
expensive, but can help to avoid missing a collision for a quickly
moving object, like a projectile.
get · iOS 13.0+
mode
TypeScript
get mode(): PhysicsBodyMode
Swift declaration
var mode: PhysicsBodyMode
The behavioral mode that controls the way the physics body moves
and interacts with other physics bodies in a simulation.
The property's default value is ``PhysicsBodyMode/dynamic``, which means
the physics body responds to forces and can collide with all other
physics bodies in the simulation.
- Important: Improve the performance of your app by applying `dynamic`
mode to the physics bodies for just entities that need to interact with
all other physics bodies, because each dynamic physics body can be
computationally expensive.
To configure the physics body so that an entity can move around the
simulation without reacting to forces, set the property to
``PhysicsBodyMode/kinematic``. Apps typically use
kinematic mode for entities the app programmatically controls,
such as in response to a control or a person's interaction.
For entities that don't need to move at all, set its physics body's mode
to ``PhysicsBodyMode/static``.
Physics bodies in `static` or `kinematic` mode can't collide with other
physics bodies with either mode, by default.
Optionally, you can add collision support for entities that have a
physics body in either static or kinematic mode by adding a
``PhysicsSimulationComponent`` to an entity that's a common ancestor to
the entities you want to collide. Then you can set
``PhysicsSimulationComponent/CollisionOptions`` to your preference.
You can change the mode of an entity's physics body at any time, but
changing it from `static` to another mode can affect your app's performance
because the transition to a non-static mode can trigger the simulation
to rebuild its state.
- Tip: Set the mode of an entity's physics body to `static` if you know
the entity doesn't ever need to move; otherwise, set the mode to
`kinematic` or `dynamic`, even if the entity isn't currently moving.
set · iOS 13.0+
mode
TypeScript
set mode(value: PhysicsBodyMode)
Swift declaration
var mode: PhysicsBodyMode
The behavioral mode that controls the way the physics body moves
and interacts with other physics bodies in a simulation.
The property's default value is ``PhysicsBodyMode/dynamic``, which means
the physics body responds to forces and can collide with all other
physics bodies in the simulation.
- Important: Improve the performance of your app by applying `dynamic`
mode to the physics bodies for just entities that need to interact with
all other physics bodies, because each dynamic physics body can be
computationally expensive.
To configure the physics body so that an entity can move around the
simulation without reacting to forces, set the property to
``PhysicsBodyMode/kinematic``. Apps typically use
kinematic mode for entities the app programmatically controls,
such as in response to a control or a person's interaction.
For entities that don't need to move at all, set its physics body's mode
to ``PhysicsBodyMode/static``.
Physics bodies in `static` or `kinematic` mode can't collide with other
physics bodies with either mode, by default.
Optionally, you can add collision support for entities that have a
physics body in either static or kinematic mode by adding a
``PhysicsSimulationComponent`` to an entity that's a common ancestor to
the entities you want to collide. Then you can set
``PhysicsSimulationComponent/CollisionOptions`` to your preference.
You can change the mode of an entity's physics body at any time, but
changing it from `static` to another mode can affect your app's performance
because the transition to a non-static mode can trigger the simulation
to rebuild its state.
- Tip: Set the mode of an entity's physics body to `static` if you know
the entity doesn't ever need to move; otherwise, set the mode to
`kinematic` or `dynamic`, even if the entity isn't currently moving.
Creates a physics body component deriving mass properties from shape and
mass.
- Parameters:
- shapes: The shape for which to estimate the rotational inertia and center of mass.
- mass: The mass of the object in kilograms.
- material: The material properties, like friction.
- mode: The simulation mode that indicates how a body responds to
forces.
Creates a physics body component deriving mass properties from shape and
density.
- Parameters:
- shapes: The shape for which to estimate the mass, rotational inertia,
and center of mass.
- density: The density of the object in kilograms per cubic meter.
- material: The material properties, like friction.
- mode: The simulation mode that indicates how a body responds to
forces.
get · iOS 13.0+
material
TypeScript
get material(): PhysicsMaterialResource
Swift declaration
var material: PhysicsMaterialResource
The physics body’s material properties, like friction.
By default, the body’s material resource is set to
``PhysicsMaterialResource/default``, which provides a modest amount of
friction and restitution (bounciness).
set · iOS 13.0+
material
TypeScript
set material(value: PhysicsMaterialResource)
Swift declaration
var material: PhysicsMaterialResource
The physics body’s material properties, like friction.
By default, the body’s material resource is set to
``PhysicsMaterialResource/default``, which provides a modest amount of
friction and restitution (bounciness).
init · iOS 13.0+
init
TypeScript
static init(): PhysicsBodyComponent
Swift declaration
init()
Creates a physics body component with default settings.
For the default settings used in a new physics body component, see the
discussions of the component’s individual properties.