Game Development Reference
In-Depth Information
gun.localToWorldMatrix *
handL.rotation = QuaternionFromMatrix(
gun.localToWorldMatrix *
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/ 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
Rotation Solver
private var speed = 0.01;
var gun: Transform; //end effector
private var ikSolver:IK1JointAnalytic = new IK1JointAnalytic();
function LateUpdate()
//IK ----
rightHandMat = ChangeCoordinateSystems(handR, gun);
leftHandMat = ChangeCoordinateSystems(handL, gun);
//Right arm
var desiredRightWristPosition: Vector3 =
(gun.localToWorldMatrix * rightHandMat).
MultiplyPoint3x4 (;
var bonesR: Transform[] = new Transform[3];
bonesR[0] = armR;
bonesR[1] = forearmR;
bonesR[2] = handR;
Search Nedrilad ::

Custom Search