Game Development Reference
In-Depth Information
{
...
}
function LateUpdate()
{
//IK ----
gun.LookAt(aimPoint.transform.position);
gun.transform.Rotate(Vector3.up,90);
}
Step 7. Play. The gun in the character's hand will orientate to
always face the red sphere as the mouse moves it around the game
environment. Any manual modification to the character's animation,
such as inverse kinematics, must occur in the LateUpdate() function—
the reason being that normal animations for the character will still
be running and are assigned to the model before LateUpdate(). If
changes to the model occur before this, baked animations will simply
replace any changes that you make with code.
Step 8. Because the character's hands are grabbing the gun, it makes
sense that they move as the gun does. To do this, we need to record
the relative location of the hands before the gun moves and then use
this to line up the hands with the gun after the gun has moved. This
requires working with 4 Ă— 4 matrices and quaternions. The following
changes you need to make to the animationControls script, shown
in Listing 3.15 , have been designed to be as painless as possible.
Listing 3.15 Storing the Relative Position between Hands and
Gun to Reset the Hand Position after the Gun Has Moved
private var speed = 0.01;
private var turnSpeed = 20.0;
private var aimPoint: GameObject;
//For IK-----------------
//right arm bones
var armR: Transform;
var forearmR: Transform;
var handR: Transform;
var rightHandMat: Matrix4x4;
//left arm bones
var armL: Transform;
var forearmL: Transform;
var handL: Transform;
var leftHandMat: Matrix4x4;
var gun: Transform; //end effector
function ChangeCoordinateSystems(from: Transform, to: Transform):
Matrix4x4
Search Nedrilad ::




Custom Search