followpath
Function
This will make an object move along a path defined by a string of daisy-chained (target to targetname) info_splinepath nodes. By default, the object will gradually orient itself to the "angles" value of each splinepath node while moving toward it. Also, if the object was rotating prior to the command, it will stop all rotation movement before it starts following the path.
Syntax
|
$<object_name> followpath $<splinepath_node> <arg> loop
|
Notes & examples
|
The choices for the optional <arg> in the command line are:
|
normalangles:
ignoreangles:
|
follow the direction of the splinepath. IOW, the object or model will "look" in the same direction it is traveling.
will ignore the angle information stored in the spline or the forward vector of the movement generated by the spline.
|
|
Making objects follow a path:
The info_splinepath entities need to be daisy-chained together by matching the target-targetname keys to one another. When the followpath command is executed, the object will move to the splinepath node specified in the command argument and follow all the other splinepaths in the chain up to the last one in an open path. If the last splinepath node's "target" key points to the first splinepath node in the chain to create a closed path, the object will stop at the node that precedes the one where it started.
In order to make some sense out of this, first take a look at Figures 1 and 2 below to see the difference between an open path and a closed path:
|
|
|
Figure 1: Open path
|
Figure 2: Closed path
|
|
In Figure 1, there are 6 splinepath nodes with targetnames "sp1" to "sp6". The first node "sp1" targets "sp2", "sp2" targets "sp3" etc. all the way to the last node "sp6". But the last node "sp6" does not target the first node "sp1" and thus the path is open.
In Figure 2, there are 6 splinepath nodes with targetnames "sp1" to "sp6" connected together the same as in Figure1 except that here, the last node "sp6" does target the first node "sp1" and thus closes the path.
So what is the difference between making making an object follow an open path or a closed path? That all depends on which pathnode you make it start following the path. In the first example, I'll instruct a scriptobject (named "ob1") to start following on "sp1" on both the open and closed paths:
|
|
|
Figure 3: Following an open path
|
Figure 4: Following a closed path
|
follow_openpath:
$ob1 follow $sp1
waitFor $object1
end
|
follow_closedpath:
$ob1 follow $sp1
waitFor $object1
end
|
|
As you can see in Figures 3 and 4, there is no difference in the result when making "ob1" follow the open or closed paths. But the reason for this is that I instructed "ob1" to start following the path on the first node "sp1" of the open path. Here, the last node in the open path happens to be the same as the node that precedes the one where it started in the closed path: "sp6". So in both cases, "ob1" sees "sp6" as being the last node in the path.
Now let's see what happens if we make "ob1" start following the path on a node other than "sp1" in both cases. I chose "sp4" for this example:
|
|
|
Figure 5: Following an open path
|
Figure 6: Following a closed path
|
follow_openpath:
$ob1 follow $sp4
waitFor $object1
end
|
follow_closedpath:
$ob1 follow $sp4
waitFor $object1
end
|
|
Ah! Now this is where the difference between an open or closed path counts. As you can see in Figure 5, "ob1" will start following the open path at "sp4" and stop at "sp6" because "sp6" is the last node in the path. But in Figure 6, "ob1" will start following the path at "sp4" and stop at "sp3" because it's the node that precedes the one where it started in the closed path. In this case, "ob1" effectively sees "sp3" as the last node in the path.
By knowing the difference, you can choose whether you want to close the path or leave it open depending on where and how you want the object to move along the path.
|
Making objects follow a path and loop:
To make an object loop the path over and over, you must add the "loop" argument at the end of the command line. Here again, leaving the path open or closing it will make a difference depending on what node you instruct the object to start following the path. Also, when the "loop" argument is used, the object will start following the path at what it considers to be the last node in the chain instead of the first node (when loop is not used).
Note: Setting the info_splinepath entity's "loop" key has absolutely no effect on func_scriptobjects or func_scriptmodels when instructed to follow or loop a path. The "loop" key only affects cameras (func_camera and func_securitycamera) instructed to orbit a path.
Let's use the same set of open and closed paths in the example above to see how this affects objects looping a path:
|
|
|
Figure 7: Looping an open path
|
Figure 8: Looping a closed path
|
follow_openpath:
$ob1 follow $sp1 loop
waitFor $object1
end
|
follow_closedpath:
$ob1 follow $sp1 loop
waitFor $object1
end
|
|
As you can see in Figures 7 and 8, there is no difference in the result when making "ob1" loop the open or closed paths. In both cases, "ob1" will start following at "sp6" and loop the entire path because in both the open and closed path examples, it considers "sp6" as the last node in the path.
Now let's see what happens if we make "ob1" start looping the path on a node other than "sp1" in both cases. I chose "sp4" for this example:
|
|
|
Figure 9: Looping an open path
|
Figure 10: Looping a closed path
|
follow_openpath:
$ob1 follow $sp4 loop
waitFor $object1
end
|
follow_closedpath:
$ob1 follow $sp4 loop
waitFor $object1
end
|
|
Here again, this is where the difference between an open or closed path counts. By observing where "ob1" starts following the path and which nodes it loops in Figure 9 and Figure 10, you can see that the result is not at all the same:
In Figure 9, "ob1" is instructed to follow the path starting at node "sp4". What happens first is that the object looks for all the nodes that can be "seen ahead of sp4" up to the last one in the path. Since the path is open, this happens to be "sp6" because that's where the path ends. Having found what it considers as the last node in the path, "ob1" jumps to it and starts looping the path:
sp6 -> sp4 -> sp5 -> sp6 -> sp4 ... etc.
In Figure 10, "ob1" is instructed to follow the path starting at node "sp4". What happens first is that the object looks for all the nodes that can be "seen ahead of sp4" up to the last one in the path. But in this case, since the path is closed, the object will "find" nodes beyond "sp6" all the way to "sp3". Remember that in a closed path, the node that precedes the one specified in the command is considered to be the last node in the path. Having found what it considers as the last node in the path, "ob1" jumps to it and starts looping the entire path:
sp3 -> sp4 -> sp5 -> sp6 -> sp1 -> sp2 -> sp3 -> sp4 ... etc.
Making an object loop predictably around a path seems more complicated because of this "start at last node" thing instead of just starting at the node specified in the command like for non-looping paths. But once you get the basic idea, it really isn't (it just makes it much harder to explain :P ).
|