Game Development Reference
In-Depth Information
Connecting SplineMgr to NPCScript
To prepare a spline curve to be used by the
splineMgr
class, we can perform the
following steps:
1. Create an empty GameObject, and set its position to (
0
,
0
,
0
). This will be the
parent node to the collection of waypoints. Name it something appropriate,
such as
curve1
.
2. Create a series of spheres named
waypoint1
,
waypoint2
, and so on. Note,
we use GameObjects instead of empty objects so that we can enable the
mesh renderer on the nodes if debugging or visualization is necessary. Our
system will require a minimum of five points and two segments.
3. Arrange these points in the editor so that they form an appealing curve that
meets your needs. Note that we interpolate the position of the waypoints only,
so rotating them will not impact the trajectory of the interpolation.
4. Create a GameObject that will be used to interpolate the curve. Name it
SplineObj
and assign it to the
headObj
reference of the
SplineMgr
class.
5. Create a
lineRenderer
component, and attach it to the
headObj
object.
Give the
lineRenderer
component 1024 position fields to start with so that
it has enough pre-allocated segments to draw our curves.
6. Your curve should look something like the one in the following screenshot: