Game Development Reference
handL.rotation = QuaternionFromMatrix(
Step 9. Play. The hands will now orientate with the gun. They don't
change position, just rotation, and therefore are a little inaccurate
when the gun is in some orientations. So far we haven't used any
inverse kinematic calculations. They start now. The objective will be to
rotate the shoulder, elbow, and wrist joint to suit the gun orientation.
Step 10. Download Chapter Three/IKplugins.zip from the Web site.
It contains two C# code files from the Locomotion project for
calculating inverse kinematics. For more on this, see http://www.unity3d
.com/support/resources/unity-extensions/locomotion-ik.html . Unzip
these files. Create a folder in the Project called Plugins and place the
IK1JointAnalytic.cs and IKSolver.cs in it.
Step 11. Now modify animationController.js to use the inverse kinematics
code to rotate the shoulders, elbows, and wrists as shown in Listing 3.16 .
Listing 3.16 Implementing an Inverse Kinematic Joint
private var speed = 0.01;
var gun: Transform; //end effector
private var ikSolver:IK1JointAnalytic = new IK1JointAnalytic();
rightHandMat = ChangeCoordinateSystems(handR, gun);
leftHandMat = ChangeCoordinateSystems(handL, gun);
var desiredRightWristPosition: Vector3 =
(gun.localToWorldMatrix * rightHandMat).
var bonesR: Transform = new Transform;
bonesR = armR;
bonesR = forearmR;
bonesR = handR;