A lot of people are dazzled about waypoints. Waypoints are nothing more than a reference point in a path or route.
Attached is an example I just coded tonight to show how waypoints are created. If you wanted to do something where an object follows the waypoints you simply create a loop that will point the object at the next waypoint and tell it to move foward.
Hope that helps you out!
---
DarkScript Source:
// Create waypoint array that will store the x, y, and z locations
global waypoint = array(0);
// These variables will be used as temporary
// variables to hold the x, y, z locations
// that get inserted into the waypoint array
global newX;
global newY;
global newZ;
global AddWaypoint = function()
{
// Obtain the array size
szArray = waypoint.Size();
// Adding 1 to the array size
// so that we can resize it for
// the new waypoint
szArray = szArray + 1;
waypoint.Resize(szArray);
// Position the size back to our original position
szArray = szArray - 1;
// Insert the table into the array
waypoint[szArray] = table(X = 0, Y = 0, Z = 0);
// Putting our x, y, z location into the array
waypoint[szArray].X = newX;
waypoint[szArray].Y = newY;
waypoint[szArray].Z = newZ;
};
global PrintWaypoint = function()
{
// Grab the total number of waypoints stored
szArray = waypoint.Size();
szArray = szArray - 1;
// Check to see if no waypoints are being stored
if (szArray == -1)
{
return;
}
// Print details about the last waypoint clicked
PrintString("Waypoint Number: " + (szArray+1).String());
PrintString("X: " + waypoint[szArray].X.String());
PrintString("Y: " + waypoint[szArray].Y.String());
PrintString("Z: " + waypoint[szArray].Z.String());
};
DBPro Source:
` Load the waypoint script
load script "waypoint.gm"
sync on
sync rate 0
color backdrop 0
load image "terrain.bmp",1
make object plain 1,100,100
xrotate object 1,-90
position object 1,0,-2,-90
texture object 1,1
do
` Check if the left mouse button was pressed
if mouseclick() = 1 then addwaypoint() : wait 300
` Resets the cursor back to 0,0 and print our last
` waypoint click if there was one
set cursor 0,0
script function "PrintWaypoint"
sync
loop
function addwaypoint()
` Was the mouse click on our object?
result = pick object(mousex(),mousey(),1,1)
if result > 0
` Calculate the world position
WX = get pick vector x() + camera position x()
WY = get pick vector y() + camera position y()
WZ = get pick vector z() + camera position z()
` Insert the world position into our script variables
script set int variable "newX",WX
script set int variable "newY",WY
script set int variable "newZ",WZ
` Execute the function that adds our new waypoint
script function "AddWaypoint"
else
` Mouse click was outside of our target area, tell the user
set cursor 0,0
print "Mouse click was outside of terrain object"
sync
endif
endfunction