impulseDirection
TypeScriptget impulseDirection(): SDKHandleSwift declarationlet impulseDirection: SIMD3<Float>Impulse direction in scene coordinate space.
struct · iOS 18.0+ · SDK 27.1
struct ContactEvents 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... } } ```
get impulseDirection(): SDKHandleSwift declarationlet impulseDirection: SIMD3<Float>Impulse direction in scene coordinate space.
get penetrationDistance(): numberSwift declarationlet penetrationDistance: FloatThe distance of overlap between the contact pair.
get point(): SDKHandleSwift declarationlet point: SIMD3<Float>Point of contact in scene coordinate space.
get normal(): SDKHandleSwift declarationlet 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 impulse(): numberSwift declarationlet impulse: FloatImpulse, the force over time of the collision, in newton-seconds
No declarations were skipped in this snapshot.