Game Development Reference
In-Depth Information
10. The
eval()
method is where the
SplineMgr
system evaluates the curve
from being called every
FixedUpdate()
. Depending on the playback mode,
it will either evaluate every frame or pause.
11. Recall that
SplineMgr
supports two playback types,
const_dt
and
const_distance
. In the
const_dt
mode, the spline is evaluated at
t+dt
every time
FixedUpdate()
is called:
if (type == ePlaybackType.const_dt)
t += dt;
12. If the playback type is
const_dist
, the
SplineMgr
class will dynamically
adjust the
dt
value for each frame so that the distance from the previous
point on the curve to the next point on the curve is approximately equal to
target_arclength
. We use sequential search instead of binary search
because it is less prone to getting stuck in high curvature segments.
13. Recall that a spline curve is defined over four control points. To build a longer
curve composed of more points, we use a sliding window technique and con-
struct tangent curves.
Every frame, we update
t
by
dt
(or dynamic
dt
) and find a point on the
curve for the relevant four control points. The four points that we pass into
the spline evaluation method are the four points around the current moving
windows view of the
ControlPoints
list:
// extract interpolated point from spline
//Vector3 vOut = new Vector3(0.0f, 0.0f,
0.0f);
vOut = Vector3.zero;
Vector3 p0 =
ControlPoints[nHead].transform.position;
Vector3 p1 =
ControlPoints[nHead+1].transform.position;
Vector3 p2 =
ControlPoints[nHead+2].transform.position;
Vector3 p3 =
ControlPoints[nHead+3].transform.position;