Creating dynamics with MEL commands
 
 
 

Maya lets you easily add dynamic properties to the objects in your scenes. All attributes that can be modified by selecting menu items, can be accessed by setting the arguments of a Maya command.

In this section you create a dynamic simulation using MEL so that the stack of barrels reacts to gravity and moves in a realistic manner. Apply a rigidBody node to all of the barrels, add a gravity field and a passive rigid body plane for the barrels to collide with.

For more information about rigid bodies and fields within dynamics in Maya, see Lesson 2: Rigid bodies and constraints and the Dynamics guide in the Maya Help.

To add rigid body nodes to the barrels using MEL

  1. Select all the barrels by typing the following:
    select -allDagObjects;

  2. Move the stack of barrels upwards along Y (by half the height of a barrel) so they are not intersecting the ground plane.
    move -r 0 (0.5*$diameter_barrel) 0;
  3. Add a gravity field to the selected geometry by entering the following in the Script Editor.
    performDynamics 1 Gravity 0;

    When a gravity field is added to the geometry, rigid body nodes are automatically added to the geometry.

To create a plane for the barrels to simulate against

  1. Make a plane for the barrels to simulate against by typing the following:
    polyPlane -height 100 -width 100;
  2. With the plane selected, add a rigid body node to the plane by typing the following:
    rigidBody -passive;

To view the simulation

  1. Click the play button on the time slider to view the dynamics simulation.