edit: got bezier line drawing working, script changed.
@BigKahuna:
Varying ship speed is pretty easy… just increase the thrust over time. I was thinking of doing something like that, possibly, by including new thrust speeds inside the waypoints. I figure I can dump a lot of data inside each waypoint and have the Follower ramp up or down to the new speed. I have a similar idea for the up vector (so that I can have the camera rotate along the path a certain way, like into ground holes or straight up without flipping out), but it’s not baked yet.
What is baked, though, is bezier waypoints!
var turnTime : int = 40;
var nextDist : float = 2.5;
static var kLineOfSightCapsuleRadius = 0.25;
var target : GameObject;
var target2 : GameObject;
var size : float = 0.5;
var drawCurve : boolean = true;
var drawHandles : boolean = true;
var drawAsLine : boolean = true;
var curveType : int = 4; // 4 = cubic bezier, 3 = quadratic
var curveSegments : float = 10.0; // how smooth the curve should be
var curveDrawType : int = 1; // 1 = spheres, 2 = line
var curveSphereSize : float = 1.0;
// Draw the waypoint pickable gizmo
function OnDrawGizmos () {
// Draw lines to the targets if they exist
ODG_LineToTarget(target);
ODG_LineToTarget(target2);
Gizmos.color = Color.green;
Gizmos.DrawWireSphere(transform.position, size);
Gizmos.DrawIcon (transform.position, "Waypoint.tif");
if (target) {
// draw bezier curve
if (drawCurve) {
var distance : float = Vector3.Distance(target.transform.position, transform.position);
var qdist : float = distance / 4.0;
var p1 : Vector3 = transform.TransformPoint(0, 0, qdist);
var p2 : Vector3 = target.transform.TransformPoint(0, 0, -qdist);
if (drawHandles) {
//debug: draw bezier "handles"
Gizmos.color = Color.red;
Gizmos.DrawLine(transform.position, p1);
Gizmos.color = Color.blue;
Gizmos.DrawLine(p2, target.transform.position);
Gizmos.color = Color.yellow;
Gizmos.DrawSphere(p1, curveSphereSize);
Gizmos.DrawSphere(p2, curveSphereSize);
}
// draw the bezier based on the distance and the number of segments
// does the rounding matter?
var jumpdist : float = 1.0 / curveSegments;
// #!FIXME: make it draw lines too
var lineStart : Vector3 = transform.position;
var lineEnd : Vector3;
if (!drawAsLine)
Gizmos.color = Color.green;
else
Gizmos.color = Color.red;
for (var i : int = 1; i < curveSegments; i++) {
lineEnd = PointOnBezier4(transform.position, p1, p2,
target.transform.position, jumpdist * i);
if (!drawAsLine)
Gizmos.DrawSphere(lineEnd, curveSphereSize);
else {
Gizmos.DrawLine(lineStart, lineEnd);
lineStart = lineEnd;
}
}
}
}
}
function PointOnBezier4(p1 : Vector3, p2 : Vector3, p3 : Vector3, p4 : Vector3, t : float) : Vector3 {
var q1 : Vector3 = Vector3.Lerp(p1, p2, t);
var q2 : Vector3 = Vector3.Lerp(p2, p3, t);
var q3 : Vector3 = Vector3.Lerp(p3, p4, t);
var r1 : Vector3 = Vector3.Lerp(q1, q2, t);
var r2 : Vector3 = Vector3.Lerp(q2, q3, t);
var r3 : Vector3 = Vector3.Lerp(r1, r2, t);
return r3;
}
// Draw the waypoint lines only when you select one of the waypoints
function OnDrawGizmosSelected () {
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, size);
Gizmos.DrawIcon (transform.position, "Waypoint.tif");
// draw "bezier" lines
}
function ODG_LineToTarget(ntarget) {
// for target 1
if (ntarget) {
if (Physics.Linecast(transform.position, ntarget.transform.position))
{
Gizmos.color = Color.red;
Gizmos.DrawLine (transform.position, ntarget.transform.position);
}
else
{
Gizmos.color = Color.green;
Gizmos.DrawLine (transform.position, ntarget.transform.position);
}
}
}
Essentially, a waypoint that has a waypoint for its target will use the Gizmos to draw the path. I’m cheating a lot – I couldn’t think of a simple way to seam together two four-point bezier curve, so I’m kind of making each waypoint like a bezier point with handles. The handles lie along the Z axis. Red points forwards, and blue points backwards.
Hopefully it’ll make sense if you try it out on some empties. Here’s a quick screenshot. Next up: bezier pathing in the Follower!
If you want a way to add WayPoints easily, check out the script above. Hope someone finds the above useful. 
