Structure

PhysicsBodyComponent

A component that defines an entity’s behavior in physics body simulations.

Declaration

struct PhysicsBodyComponent

Overview

Add a physics body component to an entity by adopting the HasPhysicsBody protocol. The ModelEntity adopts the protocol by default.

You add a physics body component to an entity to enable RealityKit’s physics simulation to compute behavior in response to forces acting upon the body, following basic rules of Newtonian mechanics.

Topics

Creating a Physics Body Component

init()

Creates a physics body component with default settings.

init(massProperties: PhysicsMassProperties, material: PhysicsMaterialResource?, mode: PhysicsBodyMode)

Creates a physics body component with the given mass properties, material, and mode.

init(shapes: [ShapeResource], density: Float, material: PhysicsMaterialResource?, mode: PhysicsBodyMode)

Creates a physics body component deriving mass properties from shape and density.

init(shapes: [ShapeResource], mass: Float, material: PhysicsMaterialResource?, mode: PhysicsBodyMode)

Creates a physics body component deriving mass properties from shape and mass.

Detecting Collisions

var isContinuousCollisionDetectionEnabled: Bool

A Boolean that controls whether the physics simulation performs continuous collision detection.

Locking Movement

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.

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.

Setting the Mode

var mode: PhysicsBodyMode

The physics body’s mode, indicating how or if it moves.

enum PhysicsBodyMode

The ways that a physics body can move in response to physical forces.

Setting Material Properties

var material: PhysicsMaterialResource

The physics body’s material properties, like friction.

class PhysicsMaterialResource

Material properties, like friction, of a physically simulated object.

Setting Mass Properties

var massProperties: PhysicsMassProperties

The physics body’s mass properties, like inertia and center of mass.

struct PhysicsMassProperties

Mass properties of a physics body.

Registering a Component Type

static func registerComponent()

Registers a new component type.

Comparing Physics Body Components

static func == (PhysicsBodyComponent, PhysicsBodyComponent) -> Bool

Indicates whether two physics body components are equal.

static func != (PhysicsBodyComponent, PhysicsBodyComponent) -> Bool

Indicates whether two physics body components are not equal.

Relationships

Conforms To

See Also

Simulating Forces and Impulses

var physicsBody: PhysicsBodyComponent?

A component that is used for physics simulations of the model entity in accordance with the laws of Newtonian mechanics.

func addForce(SIMD3<Float>, relativeTo: Entity?)

Applies a force to the physics body at its center of mass.

func addForce(SIMD3<Float>, at: SIMD3<Float>, relativeTo: Entity?)

Applies a force to the physics body at the specified position.

func addTorque(SIMD3<Float>, relativeTo: Entity?)

Applies a torque to the physics body at its center of mass.

func clearForcesAndTorques()

Clears all forces previously added to the physics body.

func applyLinearImpulse(SIMD3<Float>, relativeTo: Entity?)

Applies an impulse to the physics body at its center of mass.

func applyAngularImpulse(SIMD3<Float>, relativeTo: Entity?)

Applies an angular (torque) impulse to the physics body at its center of mass.

func applyImpulse(SIMD3<Float>, at: SIMD3<Float>, relativeTo: Entity?)

Applies an impulse to the physics body at the specified position.

func resetPhysicsTransform(recursive: Bool)

Resets the position, orientation, and velocities of the simulated physics body.

func resetPhysicsTransform(Transform, recursive: Bool)

Resets the position and velocities of the simulated physics body.

Deprecated
protocol HasPhysicsBody

An interface that enables physics simulations based on the rules of Newtonian mechanics.