Constraints Constraints allow you to control one object's position and/or rotation with one or more other objects. For example, a boat object may be constrained to the animated surface of a body of water. Constraints are essential for most forms of keyframed animation. The constraint types offered in max 7 are these:- Attachment
maintains an object on a mesh surface - Surface
maintains an object on a parametric surface - Link
allows the parenting of an object to change over time - LookAt
forces an object to keep a specified axis oriented toward a target - Orientation
rotates an object relative to the orientation of target object(s) - Path
places an object along a path or a mix of multiple paths - Position
positions an object relative to one or more target objects
In these next exercises, we'll work with most of these constraints, and often combine them to create automated mechanical setups.Attachment Constraints In this section, you will use the Attachment constraint to place a toy duck and some bubbles on the surface of a flowing body of water. You will also use the Linked XForm modifier and a loft object to attach the animated duck to a simple rope. If you wish to preview the animation you will be creating, play the rendered movie duck.mov from accompanying DVD.
1. | Open the max file attachment_constraint_begin.max from the DVD. This scene contains a rubber duck and a trough filled with flowing water (Figure 14.1). The flowing water is created with a Plane primitive, displaced with an animated procedural map.Figure 14.1. The scene to start with: a toy duck and some flowing water.
Note | The Attachment constraint will only work with target objects that can be converted to meshes. Any applied modifiers must be Object Space modifiers, as World Space modifiers, such as Displace Mesh (WSM), do not translate into meshes. |
| 2. | Select the duck, open a Left viewport, and zoom in on the duck.Before applying an Attachment constraint, always consider the pivot point of the object, as the pivot point will determine where the object will intersect the object you are attaching to. The pivot point for the duck is located in the middle of its body (Figure 14.2).Figure 14.2. The pivot point of the duck object, shown highlighted, is in the middle of the body. [View full size image] | 3. | To move the pivot point lower in the body, giving the duck a higher placement on the water, go to Affect Pivot Only mode (Hierarchy panel > Pivot tab > Adjust Pivot rollout), and move the pivot point lower on the View Y-axis (Figure 14.3). Click the Affect Pivot Only button again to exit this mode.Figure 14.3. Moving the pivot point of the duck lower will cause it to ride higher in the water. [View full size image] | 4. | To apply the Attachment constraint, go to the Camera viewport, and with the duck still selected, go to the Menu bar and click on Animation > Constraints > Attachment Constraint. In the viewport, a dotted line will appear between the duck's pivot point and the cursor (Figure 14.4).Figure 14.4. Once the Attachment constraint is applied, the dotted line indicates you can select an object to which to attach the duck.
 | 5. | Click on the water to select it as the surface to which you will attach the duck. Doing this in the Camera viewport will have the effect of making the duck disappear, as it has been aligned by default on Face #1 of the mesh, which is off-camera (Figure 14.5).Figure 14.5. Initially, the constrained object is placed on Face #1 of the target surface. [View full size image] | 6. | The Motion panel should automatically open when the constraint is assigned. If you have selected the wrong target surface, simply click the Pick Object button in the Attachment Parameters rollout and try again. | 7. | To set the initial position of the duck, click the Set Position button and click in the middle of the Camera viewport to place the duck (Figure 14.6). It may be necessary to click-and-drag to get your selection to register.Figure 14.6. The Set Position button is used to place the constrained object on a specific part of the target surface. [View full size image] Note that, by default, the duck is oriented according to the normal of the selected face, but this will be overridden later with rotational keyframes. While Align To Surface is checked, you can still rotate the duck around the target surface's normal, regardless of whether you are in Auto Key mode (previously called Animate mode) or not (Figure 14.7).Figure 14.7. Attachment-constrained objects can be manually rotated with Align To Surface activated. [View full size image] Note | Once a position has been set for the Attachment constraint, a keyframe is created at the current frame. It is possible to animate the movement of a constrained object without being in Animation mode. |
| 8. | Once you are satisfied with the initial position, turn off the Set Position button.If you scrub the Time Slider, you'll see how the duck rides the waves and rotates to maintain its alignment with the surface. Unfortunately, this movement is lost whenever the position or rotation of the object is animated. To keep this rotational information as the Attachment constraint has calculated it, you would need to position the object at frame 0, leave Align To Surface checked, and not animate its position or rotation. | 9. | Turn off Align To Surface (Attachment Parameters rollout.) This will prevent the duck from rotating according to the water's changing surface, but that rotation will be lost anyway once the duck's position is animated. Later in this section, Rotation Script controllers will be used to regain this information. Turning off Align To Surface will also cause the duck to regain its initial orientation, pointing downstream. | 10. | To allow the duck to slide a bit on the surface of the water, go to frame 80, click the Set Position button, and move the duck to a new position a little closer to the camera. A dialog will appear, asking you to confirm the animation of the object's position. Click Yes to close it. Note that you have animated this object without necessarily being in Animation mode. | 11. | Go to frame 160, and check that the Set Position button is still on. Another method for animating the position is to edit the value of the Face setting in the top of the Position area of the Attachment Parameters rollout. Incrementing the Face value will move the duck laterally across the surface. Slowly change the Face value until the duck has moved to the far side of the water (Figure 14.8). Click Set Position again to exit that mode.Figure 14.8. The position of the constrained object can be changed using the Face setting in the rollout. [View full size image] Note | The Face value will not be editable unless Set Position is active or a position key exists at the current frame. |
| 12. | At frame 250, move the duck back to the middle of the stream, where it started, though it may now be oriented differently (as in Figure 14.6). Select the key at frame 0 displayed in the track bar and Shift-drag (hold down the Shift key and the left mouse button while dragging with the mouse) to frame 250. This will clone the frame 0 key, duplicating the attachment position. If you toggle between frames 0 and 250 (Home and End keyboard shortcuts,) you will note the duck's position is not precisely the same due to the water's changing surface. |
If you scrub the Time Slider, the duck should move smoothly across the surface of the water in a rough loop. In fact, it moves too smoothly, ignoring the rippling waves. This is due to two factors. One is the way in which the Attachment constraint interpolates between keys. Constrained objects are only placed on the target surface at keys; between keys, they smoothly interpolate through space, without regard for whether they still appear to be attached to the target surface or not. This can be remedied by adding attachment keys at the points where the constrained object appears too high or too low.The exact frames at which this occurs in your version of this scene will depend on where on the surface you have set your attachment keys, but for the version of the completed scene provided on the DVD, frame 20 represents a point where the waves have risen higher, and an attachment key is needed to correct the duck's placement.For points along the duck's path where the attachment needs to be keyed, simply zoom in on the duck in a Top viewport, turn on Set Position, and click the duck's pivot point (Figure 14.9). As with the initial placement of the duck, it may be necessary to click and drag the mouse to make your selection register. Setting the new position close to the duck's pivot point will keep the new attachment keys close to the previous path.Figure 14.9. Place a refining attachment key in the Top viewport, guided by the location of the pivot point (shown enhanced in this figure). [View full size image] You can add attachment keys to refine the placement of the duck and keep it riding at the same level in the water throughout the animation (Figures 14.10 and 14.11).Figure 14.10. Before adding an attachment key, the duck is riding too low on the waves. [View full size image] Figure 14.11. Once an attachment key has been added, the duck rides at the same level in the water. [View full size image] Continue through the animation, adding refinement keys whenever the duck appears to ride too high or too low.The second factor responsible for the duck's ghost-like motion across the waves is the duck's lack of bobbing or tilting motion as it passes across the uneven surface of the waves. A limitation in the Attachment constraint makes the automatic alignment of the duck unavailable, but with some scripting, that motion can be regained.Script Controllers Script controllers allow all the powers of MAXScript to be used to calculate the values of other types of controllers. These values are passed to the object's rotation track, position track, scale track, or whatever track the controller has been applied to. This section will guide you through the creation of a short script designed to keep the duck aligned with the surface of the water. For more information on MAXScript, see the chapter on scripting in this book as well as the MAXScript Reference (Help > MAXScript Reference).
1. | With the duck still selected, go to the top of the Motion panel, and in the Assign Controller rollout, select the Rotation controller. The Rotation controller is assigned TCB Rotation by default. Click the Assign Controller button (labeled with a question mark) to choose a new controller. | 2. | Highlight the Euler XYZ controller and click OK.Note | The Euler XYZ controller lists each rotation axis separately and is useful when you wish to apply different controllers to each axis. |
| 3. | Expand the Rotation controller list to see that each axis has been assigned a Bézier Float controller (Figure 14.12).Figure 14.12. The Euler XYZ rotation controller separates each axis of rotation into a separate Bézier Float controller.
 | 4. | Select the X Rotation controller and assign a Float Script controller to it (Figure 14.13).Figure 14.13. The Float Script controller allows for custom scripting of individual rotation tracks.
 |
Working with a Script Controller Once the script controller has been applied, a dialog opens, allowing you to enter the actual script. Initially, the dialog contains only a single value, and once the script has been entered, it must end with a single value of the correct type (float), which will be applied as the X-axis rotation.The script you will be entering will cast a ray down toward the water's surface, which will reflect a ray back up, angled to correspond to the surface normal of the water. The X rotational value for the duck will be extracted from the angle of this reflected ray. The script is available on the DVD as rotational script.txt.Before you start, note that a common cause of "undefined" errors in ray-casting scripts is non-intersection. If the ray were cast from under the water's surface, then it would never intersect the water, resulting in an error. A similar error would be generated if the ray were angled off to the side of the water's surface.Tip | If you should close the Script Controller dialog and need to reopen it, select the X Rotation track in the controller list and open its Properties from the contextual menu, accessed by right-clicking. | Let's go line by line through the script. Delete the initial value and enter the following lines into the script dialog: RayFromPos = [$Duck.position.x, $Duck.position.y, $Duck.position.z + 1000]
This line makes the position from which the downward ray will be cast equal to the duck's position. An increment of 1000 units has been added to the Z-axis position to ensure that the ray is not being cast from within the wave, which would result in an error. RayToSurface = ray RayFromPos [0,0,-1]
Note | Variables set within a Script controller are not available to other scripts unless they are declared globally (see MAXScript Online Reference for more information). | This line generates the ray from the duck straight down along the World Z-axis. The three numerical values represent the ray's direction along each axis. RayAtSurface = intersectRay $water RayToSurface
This line causes the downward-casting ray to intersect the water's surface and stores the reflecting ray in the variable RayAtSurface. Keep in mind that this second ray is not a true reflection, but corresponds to the water's surface normal at the point where it is struck. EulerAtSurf = eulerangles (-RayAtSurface.dir.y*90) (RayAtSurface.dir.x*90) 0
This line converts the reflected ray's angle into X-axis and Y-axis values (the Z-axis is left at 0.) Don't be concerned if the math doesn't immediately make sense to you; just be aware that EulerAtSurf now contains a set of three Euler angles, one for each axis of rotation. QuatAtSurf = EulerAtSurf as quat
In order to apply rotational information, the duck needs to be converted into quaternion format. This format allows for smooth interpolation between rotational keys. This line converts the Euler angles of the ray into quaternion values. QuatAtSurf.x
This final line isolates the X-axis value of the quaternion, which will be applied to the X-axis rotation of the duck. Every Script controller needs to end with a simple declaration like this, of the correct type. To complete and test the script, click the Evaluate button. A number should appear in the Result pane to indicate a successful script (Figure 14.14). If a number does not appear, check the MAXScript Listener window (F11 to open) for error messages.Figure 14.14. The Script Controller window showing the completed script for determining the duck's X-axis rotation.
 Adding and Modifying Scripts We can now adapt the script we've just made for another axis and apply it using a second Script controller.
1. | The Script Controller window is modeless, so feel free to leave it open while you test the script's functionality. If you scrub the Time Slider, you should see that the duck now rotates along its X axis to align with the water's surface. To see what values are being set by the script, go to any frame and click the Evaluate button again. | 2. | Close the Script Controller editor window. | 3. | Select the Y Rotation controller and assign another Float Script controller to it. When the Script Controller editor window opens, it will automatically select all rotation tracks that have Float Script controllers assigned and enter the same script. In this case, this helpful feature is undesirable, so close the Script Controller window (copy the script to the clipboard for easy pasting later).Select only the Y Rotation track, and right-click Properties to open the Script Controller window. Replace the default value of 0 with the same script, the only difference being that the final line will refer to the Y-axis value of the quaternion: QuatAtSurf.y
|
Once both scripts have been correctly entered and evaluated and the window has been closed, the duck should accurately wobble along both its X axis (forward and back) and its Y axis (side to side) at it moves across the water's surface. An actual plastic duck wouldn't stick so tightly, though; it would overcompensate for the wave's motions. The duck's wobbling motion can be exaggerated easily by editing both scripts to multiply the final result by a factor of 1.5.
1. | Edit the final line of the X-axis script to read: QuatAtSurf.x * 1.5
| 2. | Edit the final line of the Y-axis script also: QuatAtSurf.y * 1.5
The duck now leans in a more exaggerated fashion (Figures 14.15 and 14.16).Figure 14.15. The duck at frame 59, leaning over to align with the water's surface. [View full size image] Figure 14.16. The duck at frame 59 leans over farther once a multiplication factor has been applied to its rotational script controllers. [View full size image] | 3. | The duck's Z Rotation track has not had a Script controller applied to it, so you can manually key Z-axis rotations. To turn the duck toward the direction in which it moves, click the Auto Key button to activate Animate mode, go to frame 20, and rotate the duck 30 degrees on its local Z axis (Figure 14.17).Figure 14.17. Manual keying of the duck's Z-axis rotation can be freely mixed with its scripted X-axis and Y-axis rotations. [View full size image] | 4. | At frame 75, rotate the duck 75 degrees on its local Z axis. | 5. | At frame 165, rotate the duck 60 degrees on its local Z axis. | 6. | At frame 190, rotate the duck 30 degrees on its local Z axis. | 7. | At frame 250, rotate the duck 50 degrees on its local Z axis, so that it is once again pointing downstream. Exit Auto Key mode by clicking the Auto Key button again. |
If you scrub the Time Slider, you will see that the duck's scripted rotations are now mixed with its manual Z-axis rotations, creating a realistic sense of motion atop the waves. Now that you're familiar with the Attachment constraint, it should be a simple matter to place a few bubbles on the water's surface.Simple Attachment As we saw in the initial attachment of the duck, the Attachment constraint will keep an attached object aligned with the target surface, as long as positional keyframes are not applied to the attached object. Now we will place a few bubbles on the water's surface and allow the constraint to control their alignment.
1. | Go to the Top viewport and look near the top end of the trough (upstream from the duck) to find four bubble meshes (Figure 14.18).Figure 14.18. These four bubble meshes will be constrained to the water as well. [View full size image] | 2. | Select bubble01 and apply an Attachment constraint to the position track, choosing the water surface as the target object. Be careful not to select the trough. Use the Select Objects dialog (default shortcut H), if necessary, to select the correct target surface. As before, the mesh may disappear from the viewport as it is moved by default to Face #1. | 3. | Repeat step 2 for bubble02, bubble03, and bubble04. If you go to the Camera viewport, you won't see the bubbles at all, but you can place them in the scene without selecting them visually. | 4. | Bubble04 should still be selected, and the Motion panel should be open. Go to frame 0 to avoid inadvertently adding keyframes to the bubbles. Click the Set Position button and place the bubble along the far edge of the water (Figure 14.19).Figure 14.19. Place the bubble along the water's edge. [View full size image] | 5. | Use the Select Object dialog to select each of the three remaining bubbles and set their positions near the water's edge (Figure 14.20).Figure 14.20. All four bubbles will now bob along the water's edge. [View full size image] | 6. | If you scrub the Time Slider, you will note that the bubbles ride the water's ripples, bobbing in place. For objects that need to be attached to a surface, and to remain in place with respect to the surface, standard application of the Attachment constraint is a quick and useful tool. |
As we have seen in this series of exercises, attachment can be used to keep animated objects aligned to a target surface as long as a little scripting is used, as well as to create simpler relationships with nonanimated objects. In this next exercise, we will use the Linked XForm modifier to explore another method of control.Linked XForm Up to this point in our animation, the duck's motion looks reasonably good, except that there is no apparent reason for the duck's ability to fight the water's current. This will be taken care of by attaching the duck to the yellow string. The first step in the process is to create a helper object and use it to control the midpoint of the string.
1. | The string itself is a simple loft, created from a circular shape and a path. Select string_path, activate Vertex sub-object mode, and select the middle vertex of the path (Figure 14.21).Figure 14.21. Select the middle vertex of the string path. [View full size image] | 2. | Move the vertex around and you will see that the string itself moves as well (Figure 14.22). The loft object used to create the string is dependent on the path, so altering the path alters the loft. Undo your moves to return the vertex to its original location.Figure 14.22. Moving vertices on the control path also changes the loft. [View full size image] In order to attach the middle of the string to the duck, we need a way to abstract the positioning of the middle vertex. The best tool for that is the Linked XForm modifier.Linked XForm allows you to control an object, or a sub-object selection, by linking it to another object. In this case, we will control a single selected vertex with a Dummy. | 3. | Create a Dummy (Create panel > Helpers > Standard), and use the Align tool to align the center of the Dummy with the center of the string (or string_path) (Figure 14.23).Figure 14.23. Create a Dummy and align it to the center of the string path. [View full size image] Tip | Aligning the Dummy with the object (or selection) to be controlled before linking can reduce later errors caused by offset transforms. |
| 4. | Select string_path, once again activate Vertex sub-object mode, and select the middle vertex of the path. It may already be selected, as the last sub-object selection is retained. | 5. | Without exiting sub-object mode, apply a Linked XForm modifier (Figure 14.24). It is important not to exit sub-object mode before applying the new modifier because the selection will not be passed along the modifier stack.Figure 14.24. Apply a Linked XForm modifier to control the center vertex.
Note | You may find that sub-object selections are suddenly not being passed to later modifiers. This problem often results when you accidentally exit sub-object mode while editing the modifier stack. Simply return to the modifier in which the selection is made, activate sub-object mode, and go to the next modifier. |
| 6. | Click the Pick Control Object button, and choose the Dummy. If you move the Dummy around, you will see how it now controls the midpoint of the string. |
The final step in this process is to attach the Dummy to the duck, so that the duck will appear to be constrained by the string, although the opposite will be true. For this level of control, we will be using a Link constraint.Link Constraints A Link constraint links two objects in max much the same way as the standard parenting hierarchy does, with one advantage: The link can be animated. The classic example of a situation in which you'd want to use a Link constraint is when one character hands an object to a second character. The ball needs to be linked to Person A until the moment when it is placed in the hand of Person B, at which point the link is transferred from A to B. A Link constraint allows for animated linking, as well as linking to the World (which enables the object to be freely animated, independent of any control objects).
1. | Confirm that the Dummy is still selected and that the Time Slider is at frame 0. Move the Dummy to the duck's tail until the string appears to pierce the end of it. You may need to use a User viewport (keyboard shortcut U) to accurately make this placement (Figure 14.25).Figure 14.25. Move the Dummy to the duck's tail. [View full size image] | 2. | The simplest way to link the string to the duck would be to use the Select and Link tool. Click the Select and Link icon and click and drag from the Dummy to the duck. The pointer will change to a pair of linked squares when it is hovering over a valid link target. | 3. | If you return to the Camera viewport and scrub the Time Slider, you will see that the Dummy (and the midpoint of the string) follows the duck's tail throughout the animation (Figure 14.26).Figure 14.26. Linking the Dummy to the duck causes the midpoint of the string to follow the duck's tail. [View full size image] If a continuous link were all that the scene required, Select and Link would be sufficient. But if animated linking is desired, the Link constraint is the proper choice. | 4. | With the Dummy selected, click the Unlink Selection icon to break the link just created. The Dummy will now remain motionless and not follow the duck. | 5. | In the Motion panel > Assign Controller rollout, select the top-level Transform : Position/Rotation/Scale controller, and assign a Link constraint controller to the Dummy. (As with all constraints, a Link constraint can be applied either with the Animation menu item or the Assign Controller rollout.) | 6. | The primary functions of the Link Constraint controller are handled through its Link Params rollout in the Motion panel. Link targets are listed in the Target list, with links added and deleted via the top three buttons (Add Link, Link to World, and Delete Link). The Key Mode section of the rollout pertains only to hierarchical objects, so we won't use those options in this exercise. | 7. | At frame 0, click the Add Link button and choose the duck. It should show up in the Target list, along with the first frame in which the link will be active. | 8. | Scrub the Time Slider forward to frame 180 (note that the Dummy follows the duck, just as it did with the Select and Link tool). At frame 180, click the Link to World button (Figure 14.27).Figure 14.27. Choose the World as the second link target.
 |
As long as the World is the active link target, the Dummy can be freely animated and will no longer follow the duck. At this point, we will animate the Dummy to simulate the string snapping away from the duck.Before adding any keyframed movement to the Dummy, we need to create a key that will lock the Dummy's position as of frame 180. If we don't do this, the first positional key after frame 180 will be interpolated beginning at frame 0, which will cause the Dummy's position in relation to the duck to slowly wander when it is supposed to be linked to the duck.At frame 180, go the PRS Parameters rollout (in the Motion panel, below the Link Params rollout) and click Position and Rotation in the Create Key area. We have now set position and rotation keys, even though Auto Key mode is not active.
1. | Turn on Auto Key mode and go to a Top viewport. Go to frame 195 (note that the Dummy is no longer following the duck), and move the Dummy on the View XY plane to simulate a quick snapping motion (Figure 14.28).Figure 14.28. Move the Dummy away from the duck to show the string snapping back. [View full size image] Over the remaining 55 frames of the animation, we will move the Dummy back and forth, ending with a position near the original center of the string. For progressive animation sequences like this, displaying an object's trajectory can be quite helpful. | 2. | At the top of the Motion panel, click the Trajectories button to view the Dummy's path in the viewport (Figure 14.29).Figure 14.29. Turning on Trajectories in the Motion panel shows the selected object's path. [View full size image] | 3. | Continue moving the Dummy and setting keyframes until the Dummy returns to the original midpoint of the string at frame 250 (Figure 14.30). Moving objects while Trajectories is activated can be a little sluggish, because the trajectory is constantly being recalculated.Figure 14.30. Using the displayed trajectory as your guide, animate the Dummy to bounce back to its original position. [View full size image] | 4. | Turn off Auto Key mode.If you scrub the Time Slider, you should see the string snap away from the duck at frame 180. The final touch remaining is to allow the duck to slide downstream once its link to the string is broken. | 5. | Select the duck and go to frame 180. Still using the Top viewport, note the duck's position in the water. If the Motion panel is still in Trajectories mode, change it to Parameters mode to expose the Attachment Parameters rollout. | 6. | Go to frame 250, click Set Position, and move the duck downstream.If you scrub the Time Slider between frames 180 and 250, you may see that the duck doesn't immediately head downstream. The duck's path will be affected if you set attachment keys for this time frame earlier in this exercise. In the author's version of this exercise, attachment keys were set at frames 220 and 235. In order for the duck to move directly downstream, those attachment keys need to be deleted. | 7. | For each key between frames 180 and 250, right-click on it in the track bar and choose Delete Key > duck: Attachment from the contextual menu. Once all the extraneous attachment keys are deleted, the duck should head downstream. |
If you view this animation from the Camera viewport, or view the rendered movie duck.mov from the DVD, you will see the duck riding the waves, being constrained by the string, and finally breaking free to wander downstream. To compare your results with the author's, open the attachment_constraint_complete file on the DVD.Next we will mix the Surface constraint with keyframes to control a wooden doll balancing on a swaying rope.Surface and LookAt Constraints The Surface constraint is similar to the Attachment constraint in that it constrains an object to the surface of a target object. The primary limitation of the Surface constraint is that only parametric (nonmesh) objects work as target surfaces. Eligible surfaces are the following:- Sphere, Cone, Cylinder and Torus primitives
- Single quad patches
- NURBS objects
- Loft objects
In this exercise, we will explore the use of the Surface constraint to attach a mesh to a loft object. Lofts are one of the more commonly used compound objects, particularly for organic shapes, elaborate extrusions, andas in this caserope. If you wish to preview the animation you will be creating, play the rendered movie dolls.mov on the DVD.
1. | Open the max file surface_constraint_begin.max from the DVD. This 300-frame scene contains a rope slung between two posts and a traditional Japanese kokeshi doll (Figure 14.31).Figure 14.31. The scene to start with: a doll and a rope to balance it on.
 | 2. | Scrub the Time Slider and note how the rope sags from side to side. This effect has been set up using the same technique we used in the previous section to attach the middle of the string to the duck. In this case, three vertices in the loft's path are controlled by dummies (Dummy_left, Dummy_middle, and Dummy_right). | 3. | To examine how this is set up, select the rope_path spline and examine its modifier stack (Figure 14.32).Figure 14.32. The rope is controlled via a series of SplineSelect and Linked XForm modifiers.
Tip | If at any time the rope starts acting strangely or fails to follow the dummies, check that the vertex selections are being passed down the stack and that the final Linked XForm modifier (top of the stack) is selected. |
| 4. | To attach the doll to the rope's surface, select the doll and go either to Animation > Constraints > Surface Constraint or to the Motion panel > Assign Position Controller rollout and apply the Surface constraint controller to the doll's position track. | 5. | Choose the rope as the Current Surface Object (max will not allow you to choose an ineligible object such as the rope's path). Surface-constrained objects are placed according to the target surface's UV coordinates. By default, the doll has been placed at (0,0) on the rope (Figure 14.33).Figure 14.33. The Surface constraint places objects according to the target surface's UV coordinates. [View full size image] Tip | Be very careful when you change Surface Controller UV coordinates, as inputting negative values can crash max. |
| 6. | Place the doll in the center of the rope by going to the Motion panel > Position track > Surface Controller Parameters rollout and setting V Position to 50 (Figure 14.34).Figure 14.34. Setting V Position to 50 percent will place a Surface-constrained object in the middle (lengthwise) of a target loft. [View full size image] If you use the spinners to change the U Position value, you will see the base of the doll move around the loft's circumference. Align to U should be activated so that the doll will point away from the rope's surface as it rotates. (Before continuing, confirm that U Position is set to 0 and that No Alignment is turned on.)If you scrub the Time Slider, the doll will move to follow the rope's deformations. It may appear that the doll is moving back and forth on the rope, but that visual effect is due to the rope's stretching. | 7. | To slide the doll along the rope, we will animate the V Position value. Turn on Auto Key mode, go to frame 100, and set V Position to 55. The doll will move a short distance along the rope's length. | 8. | Go to frame 250, and set V Position to 45. | 9. | To return the doll to its original position, go to frame 300 and set V Position to 50. Turn off Auto Key mode. As you scrub the Time Slider, the doll will slide from side to side, following the rope's deformations. |
The doll now seems to balance on the rope, but it's a bit static. How about adding a nice spin to the doll?Mixing Keyframes with Constraints In this section, you will rotate the doll with a manual keyframe as it follows the position track you have set up using a Surface constraint.
1. | Turn on Auto Key mode and go to frame 300. | 2. | In the Motion panel, make sure the rotation track is active (turn it on at the bottom of the PRS Parameters rollout). Still in the same rollout, click the Rotation button under Create Key to create a key at the current frame. | 3. | In the Euler Parameters rollout, set Rotation Axis to Z. | 4. | In the Key Info (Basic) rollout, set Value to 1800. Turn off Auto Key mode. |
You can now scrub the Time Slider to see the doll rotate 1800 degrees (five full rotations) over the course of the animation. Suppose we now want to add some animated objects dancing on the doll as the doll dances on the rope? The Surface constraint can help us with that as well.Recursive Constraints It is possible to use the Surface constraint to place new objects on already-constrained objects. The doll is a mesh, so it is not eligible to be a target surface, but by linking an eligible surface to the doll, this limitation can be overcome.
1. | Unhide the objects doll_right, QuadPatch_left, and QuadPatch_right.The two quad patches have already been linked to the doll and placed on its shoulders. The smaller doll will be constrained to the shoulders of the original doll, using the quad patches as target surfaces. | 2. | Select doll_right and Surface-constrain it to QuadPatch_right (Figure 14.35).Figure 14.35. Constraining the smaller doll to the linked QuadPatch gives the appearance that it is riding on the original doll's shoulders.
We'll have the smaller doll slide along the larger doll's shoulders during the animation, so turn on Auto Key mode, go to frame 100, and set V Position to 55 (Figure 14.36).Figure 14.36. The smaller doll remains attached but does not rotate. [View full size image] Note | The smaller doll does not inherit the original doll's rotation because it is not linked as a child, only constrained to follow the quad patch's surface. |
| 3. | Go to frame 250 and set V Position to 45. Turn off Auto Key mode. | 4. | To create a duplicate doll on the other shoulder, confirm that doll_right is still selected and Clone it, using Copy as the method. Name the clone doll_left. | 5. | Place the new doll on the opposite shoulder by changing its Current Surface Object (Motion Panel > Surface Controller Parameters rollout) to QuadPatch_left (Figure 14.37).Figure 14.37. Clone the smaller doll for the opposite shoulder.
 |
If you scrub the Time Slider, you will see that the new doll starts off on the far end of the shoulder, mirroring the position of the original. This is because the two quad patches are mirrors of each other; if they were not, you would need to change the keyframed V Position values to achieve mirrored movement.Next we will control the leaning of the smaller dolls with a new constraint.LookAt Constraints The LookAt constraint gives us control over any one of an object's axes, so that it will always point toward a target object, even if the target moves.
1. | Zoom out in the Front viewport, select Dummy_lookat, and in the Motion panel, turn on Trajectories mode. The path of this Dummy will be displayed (Figure 14.38).Figure 14.38. This Dummy will be used as the LookAt target. [View full size image] The two smaller dolls will be constrained to always point at this Dummy, giving them a nice animated lean throughout the animation. | 2. | Return to Parameters mode and select doll_right. Go to Animation > Constraints > LookAt Constraint and choose Dummy_lookat as the target. Turn off Add LookAt Target.The doll will immediately lie on its side, because the X axis is assigned, by default, as the axis to align. | 3. | In the LookAt Constraint rollout, set the LookAt Axis to Z to correct the doll's orientation. | 4. | Repeat steps 2 through 3 for doll_left, and return to the Camera viewport to more clearly see the doll's lean toward the target Dummy (Figure 14.39).Figure 14.39. Both dolls are oriented using the LookAt constraint. [View full size image] |
This lean has created a problemthe dolls will now intersect each other at several points in the animation. This can be avoided by changing their beginning rotation setting.
1. | With doll_right selected, go to the Motion panel, and click the Set Orientation button. This allows you to rotate the doll free of the LookAt constraint. | 2. | Rotate the doll 50 degrees on the View Z Axis (Figure 14.40).Figure 14.40. Use the Set Orientation button to change the doll's base rotation. [View full size image] | 3. | Turn off Set Orientation, and repeat the process for doll_left, except rotate it +50 degrees, so the two dolls are facing each other. This will minimize their intersection. |
To compare your results with the author's, open the surface_constraint_complete.max file from the DVD. As we have seen, the Surface and LookAt constraints can be very useful in controlling aspects of an object's animation. In the next exercise, we will explore Path and Position constraints, as well as Parameter Wiring.Path Constraints In this section, we will use Path constraints to launch a rocket and place it into orbit around a small planetoid. A Path constraint allows an object's position to be controlled by one or more paths, with weighted influences.
1. | Open the max file path_constraint_begin.max on the DVD. To preview the results of this exercise, check out launch.mov, found in the same folder. This scene contains a rotating planet, a rocket, and a small moon (Figure 14.41).Figure 14.41. A simple space scene.
Two paths have also been provided in the scene: path_launch will determine the rocket's initial course, and path_moon_orbit defines a looping path around the moon. Note that the paths have been placed so that the last node on the launch path coincides with the first node of the orbit path. When constraining an object to move directly from one path to another, it is helpful if you can align nodes in this way. | 2. | Select path_launch, go to the Modify panel, and enter Vertex sub-object mode. In the Top viewport, select the first vertex in the path (the one that coincides with the rocket's location) (Figure 14.42).Figure 14.42. Select the first node in the launch path. [View full size image] | 3. | Without exiting sub-object mode, apply a Linked XForm modifier. Pick Dummy_launchpoint as the control object. This helper will control the first point in the launch path and thereby determine the place from which the rocket will launch.We will want the rocket to rest on the planet's surface for the first 40 frames of this animation and then launch, so it is important that at frame 40 the rocket should be clearly visible. | 4. | Go to frame 40, select the Dummy, and return to the Camera viewport. We will use the Normal Align tool to place the Dummy on the planet's surface. Activate the Normal Align tool (Toolbar > Align > Normal Align), click on the Dummy, and then click and drag on the planet's surface to place the rocket near the middle of the planet's visible surface (Figure 14.43). Note how the beginning of the launch path moves with the Dummy. Click OK in the Normal Align dialog when you are satisfied with your results.Figure 14.43. Use the Normal Align tool to place the Dummy on the planet's surface. [View full size image] | 5. | To provide an animatable link between the Dummy and the planet, assign a Link constraint to the Dummy, choosing the planet as the target. Be certain to set this constraint up at frame 40, so that the Dummy's position in the time frame will remain intact.If you scrub the Time Slider, you will see that the Dummy rotates along with the planet, even prior to frame 40. Beginning with frame 41, the launch path needs to be disconnected from the planet. This can be done by adding a link to the World. | 6. | At frame 41, go to the Motion Panel, and in the Link Params rollout, click the Link to World button. If you scrub the Time Slider, you will note that the Dummy rotates with the planet only up to frame 41. |
Animating the Rocket Now we will work on setting up the rocket and placing it on the path. To begin with, there are three objects that need to follow the rocket through the scene.
1. | Select Omni_rocketflame (the source of light for the rocket's blast), PF Source 01 (a particle emitter to provide the smoke trail), and Rocket_flame (a mesh to represent the actual flame). | 2. | Use the Select and Link tool to link all three of these objects to the rocket. Use the Select Objects dialog, with Display Subtree checked, to check your hierarchy, if you wish (Figure 14.44).Figure 14.44. The rocket will be followed in the scene by three objects.
 | 3. | To place the rocket on the launch path, select the rocket and apply a Path constraint to the position track, choosing path_launch as the target path. It does not matter at what frame you create the constraint. | 4. | Go to frame 0 and confirm that the rocket is placed on the planet's surface (Figure 14.45).Figure 14.45. Using a Path constraint, the rocket has been placed on the launch path.
 | 5. | To align the rocket with the path, go to the Motion panel, and in the Path Parameters rollout, check Follow and choose the Z Axis. By default, Constant Velocity should be checked, giving the rocket a constant speed regardless of the varying distance between path vertices.By default, Path Constraint sets keyframes at the first and last frames of the animation, animating the placement of the constrained object along the path from 0 percent to 100 percent. We will need to change these settings first to keep the rocket on the planet's surface until its launch at frame 40. | 6. | In the Time Bar, select the key at frame 0 and Shift-drag it to frame 40 to create a copy of the key. This key contains only the % Along Path information, so what we have done here is prolong the rocket's placement at the beginning of the path through frame 40. | 7. | We will need to accelerate the rocket after launch, so move the key at frame 340 to frame 75. The rocket should now reach the end of the launch path by frame 75. |
Path Weighting and Percentages Beginning with frame 76, we want the rocket to orbit the moon by following a new path.
1. | In the Path Parameters rollout, click Add Path and choose path_moon_orbit.The rocket will now follow a rather bizarre trajectory, which is an average of the two paths, because they are weighted the same. Let's now animate their weights so that control of the rocket is handled by the launch path first and the orbit path second. | 2. | In the Path Parameters rollout, confirm that path_moon_orbit is still selected and set its weight to 0. This will return control to the launch path, as before. | 3. | Go to frame 76, turn on Auto Key mode, and set the orbit path's weight to 50. Still in the Path Parameters rollout, select path_launch and set its weight to 0. | 4. | These keys will transfer control of the rocket to the orbit path beginning with frame 76, but the two paths will still be averaged during frames 0 to 75. To correct this, go to frame 75 and set a Weight key of 50 for path_launch and a Weight key of 0 for path_moon_orbit.The two paths should now transfer control seamlessly between frames 75 and 76, as you can see in Track View (Figure 14.46).Figure 14.46. Control of the rocket will pass from one path to another. [View full size image] The rocket will not, however, continue along the orbit path until its % Along Path value is animated. | 5. | Confirm that Auto Key mode is still active, go to frame 76, and in the Path Options of the Path Parameters rollout, set % Along Path to 1. We start the rocket at 1 percent to avoid the momentary pause in its flight that would be caused if it went from 100 percent of the launch path to 0 percent of the orbit path, given that those two positions are the same. | 6. | We will give the rocket 2 seconds to complete its looping orbit of the moon. Go to frame 130 and set % Along Path to 100. This will cause the rocket to fly quickly around the moon twice between frames 76 and 130. | 7. | In order to propel the rocket along its path for another orbit, go to the next frame (frame 131) and set % Along Path to 3.5. Turn off Auto Key mode. The decrease in value from 100 percent to 3.5 percent is designed to overcome the pause we might otherwise see when the path repeats.We'll divide the remaining 270 frames of this animation into three more trips around the orbit path, lasting 70 frames each. | 8. | In the Time Bar, select the keys at frames 130 and 131, and copy them by Shift-dragging to frames 200 and 201, an offset of 70 frames. | 9. | Copy the keys to frames 269 and 270, and to frames 339 and 340 to complete the cycle (Figure 14.47).Figure 14.47. The rocket will travel along the launch path once (shown by the first ramp in the curve) and the orbital path four times (the final four ramps). [View full size image] |
Paths Within Paths Now that the rocket's path has been defined, suppose that we wanted to have the moon orbiting around the planet as the rocket continues to orbit around the moon. This is not difficult to achieve, so long as we preserve the relationships between the rocket and the orbit path.
1. | Unhide Dummy_moonorbit and path_moon. These objects will define a path for the moon to follow.If you scrub the Time Slider, you will note that Dummy_moonorbit is already constrained to move along the new path. Once we have linked the moon to the Dummy, we will link the orbit path to the moon. | 2. | Go to frame 0, select the moon, and Link it to Dummy_moonorbit. If you scrub the Time Slider, you will see that the moon advances along its path and is well beyond the rocket at frame 76. Clearly, this is not the desired effect. | 3. | Return to frame 0 and Unlink the moon. | 4. | Go to frame 76, and once again Link the moon to the Dummy. Now the moon will be in its original position when the rocket arrives. | 5. | Still at frame 76, select path_moon_orbit and Link it to the moon. |
If you had linked the orbit path to the moon at frame 0, a problem would crop up at frame 76, when the rocket is supposed to move from the launch path to the orbit path. Because the orbit path would have rotated from its original orientation, the paths would no longer be contiguous, causing a jump in the rocket's path between frames 75 and 76 (Figure 14.48).Figure 14.48. If the two paths are not contiguous, the rocket will "jump" from one to the other.
If you scrub the Time Slider, you will note that even though the path is rotating with the planet, the rocket's transition is seamless. Next we will use the Position constraint to control the location of a satellite.Position Constraints The Position constraint allows you to control the location of an object using one or more other objects with weighted influences. Think of it as using magnets to pull or push an object through a scene.
1. | Unhide Dummy_satellite and [Satellite]. The Dummy will be one of several objects used to control the satellite's position. | 2. | Select the satellite and apply a Position constraint, selecting Dummy_satellite as the target object. The satellite will immediately move to the Dummy's location, as the Dummy is the sole position target. | 3. | Add the planet and the moon to the Target list as well (Figure 14.49).Figure 14.49. Adding two more position targets averages the satellite's position. [View full size image] The influence of the position targets can be seen by scrubbing the Time Slider. The moon is the only position target with an animated position, and the satellite will be pulled slightly toward the moon as it moves. | 4. | To give the Dummy greater influence over the satellite's position, select Dummy_satellite in the Target list (Position Constraint rollout) and set its weight to 100. | 5. | Select Dummy_satellite, and turn on Auto Key mode. First, we'll use the Dummy to move the satellite close to the rocket when it goes into orbit. | 6. | Go to frame 75, and in the Top viewport, move the Dummy closer to the rocket's launch path (Figure 14.50). Note how the satellite is "pushed" along ahead of the Dummy.Figure 14.50. Animate the Dummy's position to move the satellite. [View full size image] | 7. | In the Camera viewport, move the Dummy up on the View Z Axis to approximately Z = 70 to pull the satellite higher in the viewport. | 8. | As the scene progresses, we'll pull the satellite in tighter on the moon. Go to frame 140, and in the Top viewport, move the Dummy to approximately X = 70, Y = 10, so that the satellite follows the moon. | 9. | Go to frame 200, and move the Dummy to near X = 13, Y = 220. | 10. | Finally, go to the last frame of the animation, and move the Dummy to near X = 115, Y = 550 (Figure 14.51).Figure 14.51. The path of the satellite's position target (shown in Trajectory mode). [View full size image] | 11. | Return to the Camera viewport and scrub the Time Slider to see how the satellite swoops through the scene. Note that the satellite almost leaves the frame, but not quite. We can accelerate it out of the frame by animating the position targets' weighting. | 12. | Select the satellite, and in the Motion panel, set the weight of the "Planet" and "Moon" position targets to 30. Turn off Auto Key mode.The satellite will now follow the Dummy more closely as the scene progresses, due to the lessening influence of the other two position targets. |
Something is still missing from this scenewhat is a rocket launch without explosive effects? In the next section, we will add some excitement to this scene and explore the use of manipulators for rigging animations. |