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,009 views  Rating:
(1 rating)
Page 2 of 4

Now its time to make these locators into goals. We'll set up one completely with all of its expressions and then add the second.

10. Select the particle and the freezeField0 and choose particles>goal.

11. Open the attribute editor for the particle shape. In the section for goal weights and objects hit the button for goalWeight0PP and the button for goalWorldPosition0PP.

Whenever you add a goal to this particle a new set of these buttons will appear. Each goal will be numbered starting with zero. This is why I named the first locator "freezeField0." it makes it easier to keep track of what's going on when I start writing expressions.

12. In the per-particle array attributes, right-click over the goalWeight0PP attribute and choose creation expression.

13. In the expression editor enter

 particleShape1.goalWeight0PP=0;

This essentially turns off the goal, but that's ok. for this exercise the goal is really a positional locator. It doesn't need to attract or affect the particles at all.

14. In the expression editor switch to "runtime before dynamics"

15. The first thing we'll do is create a variable to hold the information contained in the goalWorldPosition0PP attribute. We'll call the vairable "$goal0Pos".

The variable will have to be a vector as the goal's position is a vector.

Enter this:

vector $goal0Pos=particleShape1.goalWorldPosition0PP;

Tip: Try switching the particle type to numeric and hit the add attribute for current render type button. In the field for attribute name enter goalWorldPosition0PP. When you play the animation you can see this attribute expressed as a vector in the perspective window.

16. Next we'll create a variable to contain the particle's positionPP, we'll call it $pos.

Enter this line in the expression editor below the previous one:

vector $pos=particleShape1.position;

17. Now we'll create a distance variable for the range of the field. This is already visually represented by the fieldRange sphere we created who's scale is related to the fieldSize attribute on the freezeField locator.

The range is essentially the radius of the sphere or half the field size attribute. Enter this in the next line of the expression editor:

float $range0=.5*freezeField0.fieldSize;

18. The heart of this expression will be a conditional statement that says "if the absolute value of the difference between the particle's position and the goal's world position is less that the size of the freeze field's range, set the velocity of the particle to zero."