Adverti horiz upsell
Using Expressions in Maya 7: goalWeight and goalWorldPositionPP.
Using Expressions in Maya 7: goalWeight and goalWorldPositionPP.
robotball, added 2005-10-10 11:43:09 UTC 55,012 views  Rating:
(1 rating)
Page 3 of 4

To do this we need a couple more variables and the conditional statement.

First, a vector variable to representthe size of the field's range. Enter this in the expression editor:

vector $distance0=<<$range0,$range0,$range0>>;


19. Then add a variable for the particle's velocity:

vector $velo=particleShape1.velocity;


20. And the conditional statement:

if (abs($pos-$goal0Pos)<$distance0)
$velo=0;


21. And finally we need to set the velocity of the particles to the $velo variable:

particleShape1.velocity=$velo;


Altogether the runtime expression should look like this:

vector $goal0Pos=particleShape1.goalWorldPosition0PP;

vector $pos=particleShape1.position;

float $range0=.5*freezeField0.fieldSize;

vector $distance0=<<$range0,$range0,$range0>>;

vector $velo=particleShape1.velocity;

if (abs($pos-$goal0Pos)<$distance0)
$velo=0;

particleShape1.velocity=$velo;


Test out the animation.

As the particles come within the edge of the range, represented by the sphere, they will stop moving.

Try animating the position of the freeze field and the size of the range. Once you do this you should say to your self "big deal, all that work for that?"

Ok, not exactly Episode III quality stuff here, but, once again, this tutorial is meant to get you familiar with the new per particle goal attributes in Maya 7. It becomes slightly more interesting when we add a second goal.

22. Select the particle shape and the freezeField1 object. Choose particle>goal.

23. Open up the attribute editor for the particle shape. Notice that a new set of buttons has been added to the goal weights and objects folder. Hit the buttons for create goalWeight1PP and create goalWorldPosition1PP.

24. Now we just have to edit the expressions to add the second freeze field.

Open up the expression editor and switch to creation expressions. Change it so that it reads:

particleShape1.goalWeight0PP=0; particleShape1.goalWeight1PP=0;


25. Switch to runtime before dynamics and edit the variables so that it reads:

vector $goal0Pos=particleShape1.goalWorldPosition0PP; vector $goal1Pos=particleShape1.goalWorldPosition1PP;

vector $pos=particleShape1.position;

float $range0=.5*freezeField0.fieldSize;
float $range1=.5*freezeField1.fieldSize;

vector $distance0=<<$range0,$range0,$range0>>;
vector $distance1=<<$range1,$range1,$range1>>;

vector $velo=particleShape1.velocity;


26. Now we'll change the conditional expression so that it says "if the absolute value of the difference between the particle's position and the freezeField0's world position is less that the size of the freezeField0's range OR the difference between the particle's position and the freezeField1's world position is less that the size of the freezeField1's range, set the velocity of the particle to zero." The syntax for OR in the expression editor is "||".