A constraint that applies inverse kinematics to make a chain of nodes “reach” toward a target point.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
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:
Build a hierarchy of nodes whose
pivotproperties 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
pivotproperty should be placed so that adjusting its
rotationproperty 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.
chainproperty 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).
Apply the IK constraint to the end effector node of the chain with that node’s
constraintsproperty. In the robot arm example, the end effector is the hand or tool at the end of the arm.
(Optional) Limit the range of motion of one or more joints in the chain with the
Max Allowed Rotation Angle: for Joint:
To set the constrained nodes in motion, provide a target position for the constraint with its
targetproperty. You can animate a change to this property