Page 1231 - Kitab3DsMax
P. 1231
pathObj = $Dummy01
fishObj = $Fish1/FishBody
relPos = [0,-150,-50] -- How close the fish is to the path
animate on
(
for t = 1 to 100 do at time t
(
fishObj.position = pathObj.position + relPos
) Chapter 49: Automating with MAXScript
)
3. Select the Camera01 viewport. Choose Tools ➪ Evaluate All (or press Ctrl+E) to evaluate all the
MAXScript in the Editor window, right-click the Camera01 viewport to activate it, and click the
Play Animation button.
The fish rigidly follows the dummy object’s path. Figure 49.15 shows one frame of this animation.
FIGURE 49.15
First attempt at making the fish follow a path
Now you’ll explain the MAXScript entered in the previous tutorial. The first few lines create some variables
that the rest of the script uses. pathObj tells the name of the object that the fish will follow, and fishObj
is the name of the fish’s body. (Notice that you can reference parts of the group hierarchy by using the
object name, a forward slash, and then a child part.) Why bother creating a variable for the fish object?
After you get this first fish working, you want to apply the same script to another fish. All you have to do is
rename Fish1 as Fish2, re-execute the script, and you’re finished!
1183