Instance Method

contactTestBetweenBody:andBody:options:

Checks for contacts between two physics bodies.

Declaration

- (NSArray<SCNPhysicsContact *> *)contactTestBetweenBody:(SCNPhysicsBody *)bodyA andBody:(SCNPhysicsBody *)bodyB options:(NSDictionary<SCNPhysicsTestOption, id> *)options;

Parameters

bodyA

The first body (to test for contact with the second).

bodyB

The second body (to test for contact with the first).

options

A dictionary of options affecting the test, or nil to use default options. For applicable keys and the possible values, see Physics Test Options Keys.

Return Value

An array of SCNPhysicsContact objects describing contacts between the two bodies, or nil if the bodies are not in contact.

Discussion

SceneKit sends messages to the physics world’s contactDelegate object only when collisions occur between bodies whose collisionBitMask and categoryBitMask properties overlap, and only for collisions between certain types of bodies. (For details, see SCNPhysicsBodyType.) Use this method to directly test for contacts between any two bodies at a time of your choosing. For example, to implement a game where the player character can pick up an item, you might call this method when the player presses the “pick up” button to see if the player character is in contact with the item to be picked up.

See Also

Detecting Contacts Between Physics Bodies

contactDelegate

A delegate that is called when two physics bodies come in contact with each other.

- contactTestWithBody:options:

Checks for contacts between one physics body and any other bodies in the physics world.