Graphics Reference
In-Depth Information
interpolation takes (the Time.deltaTime multiplied by pathSmoothing) and therefore how
much the rotation along the waypoint path should be smoothed out:
moveVec= Vector3.Lerp( moveVec,
targetMoveVec, Time.deltaTime *
pathSmoothing );
When the actual translation of the transform happens, the moveVec vector is multi-
plied by moveSpeed and, in turn, multiplied by Time.deltaTime to keep everything time
based:
myTransform.Translate( moveVec * moveSpeed *
Time.deltaTime );
MoveForward();
Rotating myTransform toward the target waypoint is optional. The faceWaypoints
Boolean variable is intended to be set in the Unity editor Inspector window. When face-
Waypoints is true, the rotation is carried out by a call to TurnTowardTarget, passing in the
current waypoint transform:
if( faceWaypoints )
{
TurnTowardTarget
( currentWaypointTransform );
}
}
break;
Next in the UpdateAI() function are the steering behaviors, all ready for use by the
example games from this topic, Metal Vehicle Doom and Tank Bat tl e .
AIState.steer_to_waypoint starts by checking that the initialization occurred (didInit
should be true) and that the last waypoint has not been reached. If all is well, a call to
UpdateWaypoints() will make sure that the current waypoint held by the variable current
WaypointTransform is the correct one:
case AIState.steer_to_waypoint:
// make sure we have been initialized before trying
// to access waypoints
if( !didInit && !reachedLastWaypoint )
return;
UpdateWaypoints();
It may be possible that currentWaypointTransform does not contain a waypoint. If
that is the case, the function drops out:
if( currentWaypointTransform==null )
{
// it may be possible that this function gets
// called before waypoints have been set up,
// so we catch any nulls here
return;
}
Search WWH ::




Custom Search