Graphics Reference
In-Depth Information
myTransform.position = wantedPosition;
myTransform.LookAt( target.position + lookAtAdjustVector );
}
}
4.6.1.1 Script Breakdown
All camera scripts used with the framework should implement a SetTarget function.
SetTarget takes a single parameter of type Transform to put into the variable named target:
public override void SetTarget( Transform aTarget )
{
target= aTarget;
}
It may come as a surprise that the main update to the camera happens within
LateUpdate() and not within the Update or FixedUpdate function. The reason for this is
that we prefer everything physics-wise to have been updated before moving the camera—
which should have happened by LateUpdate()—and in doing so, there should be no dis-
crepancies between the positions of our target objects between the end of the camera
update and the drawing of the next frame. Drawing at the wrong time could cause a jitter-
ing effect as the objects we are following are updated after the camera positioning.
At the start of LateUpdate(), there are the usual null checks to make sure that we have
both a target and a cached version of the camera's transform:
void LateUpdate ()
{
if ( target == null )
return;
if ( myTransform==null )
{
myTransform=Transform;
}
The script interpolates heights and rotation values. Before the interpolation can hap-
pen, we need to find out what the target height and rotations are as well as what the current
height and rotations are. The wantedHeight variable is a float. We add the value of the public
variable height to it, allowing target height adjustment to happen by setting it in the editor:
wantedHeight = target.position.y + height;
currentHeight = myTransform.position.y;
wantedRotationAngle = target.eulerAngles.y;
currentRotationAngle = myTransform.eulerAngles.y;
Search WWH ::




Custom Search