If the distance between the root and the effector is greater that the sum of the length of the bones the chain should stretch.
Open the scene Stretchy_Bones from this issues DVD. Select the Stretchy_Bones null object and press [Alt] + [9] to open an ICE Tree. From the Create menu choose ICE Tree to create an empty ICE Tree. The idea of stretchy bones or limb stretching is quite simple. If the distance between the root and the effector is greater than the sum of the bones, the bones should stretch. But if the distance is less, the bones should stay unaffected at their default length.
Get a Get Data node and double-click on it to open its PPG. Click the Explorer button and expand the tree root > Kinematics > Global Transform and select the Pos. Get a second Get Data node and type eff.kine.global.pos in the Get Data textbox to get the position for the effector as well. The next step is to calculate the distance between the two objects, so get a Get Distance Between node. Connect the root.kine.global.pos node to the First input of the Get Distance Between node and the eff.kine.global.pos node to the Second input.
Get a Scalar node, open its PPG and enter 4 as the Value. This will set the default length of the First_Bone. Get a second Scalar node and set its value to 3. This will be the default length of the Second_Bone. Get an Add node and connect the first Scalar node to its Value1 input and the second Scalar node to its Value2 input.
Get a Greater Than (>) node, an If node and two Divide by Scalar nodes. Connect the Get Distance Between node to the First input of the Greater Than node and the Add node to the Second input. Connect the Greater Than node to the Condition input of the If node.
To set the new length for each bone you must first determine the ratio of the individual bone’s length and the distance of the root and effector. Connect the Add node to the Value input of the first Divide by Scalar nodes and the Scalar node (with the value 4) to the Divide By input. Then connect the Divide by Scalar node to the Divide By input of the second Divide by Scalar node. Connect the Get Distance Between node to the Value input. Connect the Divide by Scalar node to the If True input of the If node. Connect the Scalar node (with the value 4) to the If False input.
Get a Set Data node and connect the If node to the Value input and open its PPG. Click the Explorer button and expand the Root > Bone > Chain Bone and click the Length. Connect the Set Data node to the Port1 input of the ICE Tree.
To set the length of the Second_Bone repeat the procedure, but use the second Scalar node (with the value 3). Please use the screenshot as reference.
The project files used in this tutorial can be found at:
http://www.redi-vivus.com/Caffeineabuse/Stretchy_Bones.zip
Quick tip
The technique used is by no means limited to two bone chains. To use more bones simply add the corresponding Scalar nodes to the Add node, use the Divide by Scalar to get the division factor and connect it to the Set Data node.
Read the full post>>