One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

Contact

struct · iOS 18.0+ · SDK 27.1

struct Contact

Events associated with collisions. To subscribe to a collision event, import Combine, create a property of type <doc://com.apple.documentation/documentation/combine/cancellable> so that you maintain a reference to the subscription, then call ``RealityKit/Scene/subscribe(to:on:_:)`` or ``RealityKit/Scene/subscribe(to:on:componentType:_:)`` and provide a closure. The closure is passed an ``RealityKit/Scene/Event`` object that contains information relevant to the type of event you subscribed to. Here's an example of subscribing to the collision begain event and retrieving the two entities involved in the collision: ```swift import AppKit import RealityKit import Combine class GameViewController: NSViewController { @IBOutlet var arView: ARView! var collisionSubscription:Cancellable? override func awakeFromNib() { let boxAnchor = try! Experience.loadBox() arView.scene.anchors.append(boxAnchor) collisionSubscription = arView.scene.subscribe( to: CollisionEvents.Began.self, on: boxAnchor ) { event in print("collision started") let firstEntity = event.entityA let secondEntity = event.entityB // Take appropriate action... } } } ``` You can also create a function to respond to the event rather than a closure by using <doc://com.apple.documentation/documentation/combine/publisher/sink(receivecompletion:receivevalue:)>. Here's an example of using a function to respond to a collision event: ```swift import AppKit import RealityKit import Combine class GameViewController: NSViewController { @IBOutlet var arView: ARView! var collisionSubscription:Cancellable? override func awakeFromNib() { let boxAnchor = try! Experience.loadBox() arView.scene.anchors.append(boxAnchor) collisionSubscription = arView.scene.publisher(for: CollisionEvents.Began.self, on:nil).sink(receiveValue: onCollisionBegan) } private func onCollisionBegan(_ event: CollisionEvents.Began) { print("collision started") let firstEntity = event.entityA let secondEntity = event.entityB // Take appropriate action... } } ```

Members (5)

get · iOS 18.0+

impulseDirection

TypeScript
get impulseDirection(): SDKHandle
Swift declaration
let impulseDirection: SIMD3<Float>

Impulse direction in scene coordinate space.

get · iOS 18.0+

penetrationDistance

TypeScript
get penetrationDistance(): number
Swift declaration
let penetrationDistance: Float

The distance of overlap between the contact pair.

get · iOS 18.0+

point

TypeScript
get point(): SDKHandle
Swift declaration
let point: SIMD3<Float>

Point of contact in scene coordinate space.

get · iOS 18.0+

normal

TypeScript
get normal(): SDKHandle
Swift declaration
let normal: SIMD3<Float>

The normal of the contacting surfaces at the contact point. The normal direction points from the second shape to the first shape in scene coordinate space.

get · iOS 18.0+

impulse

TypeScript
get impulse(): number
Swift declaration
let impulse: Float

Impulse, the force over time of the collision, in newton-seconds

Skipped declarations

No declarations were skipped in this snapshot.

All RealityFoundation types →