One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

ForceEffectProtocol

protocol · iOS 18.0+ · SDK 27.1

protocol ForceEffectProtocol

A protocol that defines a custom force effect. A custom force effect is a function of a set of input rigid body attributes and returns force-like vector quantities. You can declare this custom force effect's input types (``ForceEffectProtocol/parameterTypes-4wuau``) and output types (``ForceEffectProtocol/forceMode``) by conforming to `ForceEffectProtocol`. For example, you can declare a custom force effect that depends on rigid bodies' position and mass, and computes acceleration for each rigid body. ```swift struct MyCustomForce : ForceEffectProtocol { var parameterTypes: PhysicsBodyParameterTypes { [.position, .mass] } var forceMode: ForceMode = .acceleration func update(parameters: inout ForceEffectParameters) { } } ``` Register your custom force effect to enable the physics system to compute forces affected by rigid bodies. ```swift MyCustomForce.register() ``` At each physics update, the ``ForceEffectProtocol/update(parameters:)-52e1i`` method receives the declared inputs from ``ForceEffectParameters``. You can set the output forces for each rigid body with ``ForceEffectParameters/setForce(_:index:)``. Sometimes, you may need to access properties from both your custom force effect and the current context while computing forces in the update function. The ``ForceEffectProtocol/register(_:)-1zt9t`` method accepts an optional closure that allows you to capture the necessary properties. If you provide this closure to the register method, the update method is not required. ```swift struct MyCustomForceClosure: ForceEffectProtocol { var forceMode: RealityFoundation.ForceMode = .force var parameterTypes: PhysicsBodyParameterTypes { [.position, .mass] } let customProperty: Double = 1 } let contextualProperty: Double = 1 MyCustomForceClosure.register { event in // Access the effect property via `event.effect.customProperty`. // Access the input rigid body attributes via `event.parameters`. // Access the contextual property directly by `contextualProperty`. } ```

Members (2)

get · iOS 18.0+

parameterTypes

Swift declaration
var parameterTypes: PhysicsBodyParameterTypes { get }

Positions are returned by default to effect handlers.

method · iOS 18.0+

update

Swift declaration
func update(parameters: inout ForceEffectParameters)

Outputs zero forces and torques by default.

Omit the output parameters from the call. The result contains $ret and $out, with parameters inside $out.

Skipped declarations

2 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

ForceEffectProtocol.register(_:)

Static protocol requirements cannot be called through an instance.

ForceEffectProtocol.register(_:)

Static protocol requirements cannot be called through an instance.

All RealityFoundation types →