Work with position, velocity, and acceleration

 
 
 

To create various types of particle motion, you can assign vector values to the position, velocity, or acceleration attribute. See Write runtime expressions for examples of working with these attributes.

Unless you have a solid grasp of physics, avoid setting a combination of the position, velocity, and acceleration attributes.

To give a smooth, random motion to particles with a runtime expression, use a random number function such as sphrand to assign random numbers to the particle shape’s acceleration attribute. A change in acceleration always gives smooth motion no matter how abruptly its value changes.

To give a jittery random motion to particles with a runtime expression, use a random number function such as sphrand to assign random numbers to the particle shape’s velocity or position attributes.

See Introduction to random number functions for details on how to use random number functions.

If an expression and a dynamic field control an object’s position, velocity, or acceleration, Maya calculates the expression’s effect first, then adds the field’s effect.

NoteIf dynamics and an expression influence position, velocity, or acceleration the instant at which the expression executes, the resulting object motion is affected. If the expression executes before dynamics, Maya computes the dynamics using the value assigned by the expression. If the expression executes after dynamics, Maya calculates dynamics based on any attribute values left over from the previous frame or values generated by an input ramp.

To set whether expressions execute before or after dynamics, select the particle object, display the Attribute Editor, and turn Expressions After Dynamics on or off.

Example

Suppose a particle drops under the influence of a gravity field with default gravity options. Gravity accelerates the particle at 9.8 units per second per second down the Y-axis. In other words, the default acceleration of gravity is <<0,-9.8,0>>.

Suppose further you write the following runtime expression for the particle:

velocity = velocity + <<1,0,0>>;

As each frame plays, Maya first calculates the particle’s velocity from the expression statement. The velocity increases 1 unit per second in an X-axis direction. Maya then adds the gravitational acceleration to the velocity. Maya uses the combined result to compute the particle’s position.

Of course, you won’t see this calculation process. The frame displays the particle in the appropriate position after all computation.

The expression adds the constant <<1,0,0>> to the particle’s velocity each frame as the animation plays. This makes the particle move with increasing velocity in an X direction as the time increases. An increasing velocity is the same as acceleration.

The acceleration attribute works differently than the position or velocity attributes in an important way. Maya initializes its value to <<0,0,0>> before each frame. If the oversample level is greater than 1, this initialization occurs before each timestep.

Example

Suppose you write the following runtime expression for a five-particle object unaffected by gravity:

acceleration = acceleration + <<0,1,0>>;

Rather than adding <<0,1,0>> to the acceleration value each frame, acceleration remains a constant <<0,1,0>> for each of the particles. This happens because Maya initializes the value of acceleration to <<0,0,0>> before each frame.

Suppose you connect the particle object to gravity with default settings. The acceleration of the particle becomes <<0,1,0>> plus <<0,-9.8,0>>, which equals <<0,-8.8,0>>. The acceleration assigned in the expression slows the downward acceleration of the gravity.

Suppose you change the previous expression to this:

acceleration = acceleration + sphrand(3);

Because Maya sets acceleration to <<0,0,0>> before each frame, the statement has the same result as the following statement:

acceleration = sphrand(3);

As each frame plays, Maya first calculates each particle’s acceleration from the expression statement. Each particle receives the result of the sphrand(3) function.

The sphrand(3) function provides a vector whose randomly selected components reside within a spherical region centered at the origin with radius 3. Each particle receives a different vector value.

Finally, Maya adds gravity’s acceleration to the expression acceleration resulting from sphrand(3). The frame displays each particle in the resulting position.

Because of the random values resulting from the expression, each particle has an acceleration that differs slightly from gravity in direction and magnitude. Because the sphrand(3) function executes for each particle each frame, the acceleration of each particle varies each frame.

This example shows that you can take advantage of the additive effect of fields and the acceleration attribute to create custom field effects.

Tip

You can turn off the effect of all fields on a particle shape node attribute by setting its dynamicsWeight attribute to 0.