Class

SCNIKConstraint

A constraint that applies inverse kinematics to make a chain of nodes “reach” toward a target point.

Declaration

@interface SCNIKConstraint : SCNConstraint

Overview

Figure 1

An IK constraint moving a chain of nodes toward a target point

Inverse kinematics (IK) is an iterative process that finds positions for the joints connecting a chain of rigid bodies in order to move the body at the end of that chain as close as possible to a desired point in space. For example, a chain of bodies might model a robot arm, and the node at the end of the chain—called an end effector—might model the hand or tool at the end of the arm. To create IK-based behavior in a SceneKit app or game, follow these steps:

  1. Build a hierarchy of nodes whose position and pivot properties describe the joints between them. For example, the node representing a robot’s lower arm should be a child of its upper arm node, and the lower arm node’s pivot property should be placed so that adjusting its rotation property appears to bend the arm at an elbow joint. The robot’s hand should in turn be a child node of the lower arm node.

  2. Create an SCNIKConstraint object whose chainRootNode property refers to the highest node in the hierarchy whose orientation should be adjusted by the constraint. Continuing the previous example, the root of the chain should be the node containing the upper arm (not the robot’s body, whose orientation remains fixed).

  3. Apply the IK constraint to the end effector node of the chain with that node’s constraints property. In the robot arm example, the end effector is the hand or tool at the end of the arm.

  4. (Optional) Limit the range of motion of one or more joints in the chain with the setMaxAllowedRotationAngle:forJoint: method.

  5. To set the constrained nodes in motion, provide a target position for the constraint with its targetPosition property. You can animate a change to this property

Topics

Creating an Inverse Kinematics Constraint

- initWithChainRootNode:

Initializes an inverse kinematics constraint whose chain of nodes begins with the specified node.

+ inverseKinematicsConstraintWithChainRootNode:

Creates an inverse kinematics constraint whose chain of nodes begins with the specified node.

Adjusting the Constraint’s Limits of Motion

chainRootNode

The parent node of the hierarchy affected by the constraint.

- maxAllowedRotationAngleForJoint:

Returns the rotation limit, in degrees, for the specified node.

- setMaxAllowedRotationAngle:forJoint:

Sets the rotation limit, in degrees, for the specified node.

Applying Inverse Kinematics to the Constrained Node

targetPosition

The desired position for the constrained node, in the scene’s world coordinate space. Animatable.

Relationships

Inherits From

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software