simulationState
TypeScriptget simulationState(): (ForceEffectComponent_SimulationState) | nullSwift declarationvar simulationState: ForceEffectComponent.SimulationState?The desired state of the simulation.
struct · iOS 18.0+ · SDK 27.1
struct ForceEffectComponentA component that defines the forces that affect an entity, including custom forces that you define. After you assign a `ForceEffectComponent` to an entity, the force effects in the component apply each physics update for as long as the component and force effects exist. Each ``ForceEffect`` updates sequentially while the physics system accumulates its forces. The center frame of each ``ForceEffect`` coincides with and moves alongside the entity’s position and orientation. To offset this center frame, set the position and orientation. - Note: You can set the ``ForceEffectComponent/simulationState-swift.property`` parameter to ``ForceEffectComponent/SimulationState/pause`` if you want to apply forces later. ### Create forces Use ``ConstantForceEffect`` to apply a constant force in a direction: ```swift let constantForceEffect = ForceEffect(effect: ConstantForceEffect(strength: 1, direction: [1, 0, 0])) ``` RealityKit provides a set of useful forces you can use with `ForceEffectComponent`: - ``ConstantForceEffect`` - ``ConstantRadialForceEffect`` - ``DragForceEffect`` - ``RadialForceEffect`` - ``TurbulenceForceEffect`` - ``VortexForceEffect`` ### Create custom forces To create a custom force effect, define a structure that implements ``ForceEffectProtocol``, then create an instance of ``ForceEffectBase`` with your custom `ForceEffectProtocol` implementation: ```swift // CustomForce implements ForceEffectProtocol, and has a custom parameter, thrustersActive, that determines how the system applies your force to a physics body. let thrusterForce = CustomForce(thrustersActive: true) // Create an instance of ForceEffectBase using your custom force. let thursterForceEffect = ForceEffect(effect: thrusterForce) ``` - Note: To apply force to a physics body with a custom `ForceEffectProtocol`, you must implement and apply forces in ``ForceEffectProtocol/update(parameters:)``. ### Apply forces You can apply multiple forces to your entity at once by including them in `ForceEffectComponent`: ```swift let forceEffectComponent = ForceEffectComponent(effects: [constantForceEffect, thrusterForceEffect]) entity.components.set(forceEffectComponent) ```
get simulationState(): (ForceEffectComponent_SimulationState) | nullSwift declarationvar simulationState: ForceEffectComponent.SimulationState?The desired state of the simulation.
set simulationState(value: (ForceEffectComponent_SimulationState) | null)Swift declarationvar simulationState: ForceEffectComponent.SimulationState?The desired state of the simulation.
static initEffect(effect: SDKHandle): ForceEffectComponentSwift declarationinit(effect: any ForceEffectBase)Creates a force effect component with a single force effect, and automatically plays it. - Parameters: - effect: The effect to simulate forces with.
static initEffectsSimulationState(effects: Array<SDKHandle>, simulationState?: ForceEffectComponent_SimulationState): ForceEffectComponentSwift declarationinit(effects: [any ForceEffectBase], simulationState: ForceEffectComponent.SimulationState = .start)Creates a force effect component. - Parameters: - effects: Array of effects to simulate forces with. Forces generated by each effect will be summed. - simulationState: The simulation state request, the force effect automatically starts to play by default.
get effects(): Array<SDKHandle>Swift declarationvar effects: [any ForceEffectBase]One or more effects used to simulate forces. Forces from each effect will be summed.
set effects(value: Array<SDKHandle>)Swift declarationvar effects: [any ForceEffectBase]One or more effects used to simulate forces. Forces from each effect will be summed.
No declarations were skipped in this snapshot.