MEL Script to make wind change directions


#1

I would like to make a wind field in maya that randomly changes directions. I’ve begun by using a simple random number generator and one direction of wind, but it isn’t working. Here’s the code:

int $randomXDirection = rand(1, 2);
airField1.DirectionX = randomXDirection;

I get this error message:
// Error: Invalid use of Maya object “randomXDirection”.

Why am I getting this error? How do I fix this?


#2

try this

float $randomXDirection = rand(1, 2);

airField1.DirectionX = $randomXDirection;

or this

// will look more natural than what random gives you for every frame

// add 1 to get a noise value between 1 and 2.

float $randomXDirection = (noise(time) + 1);

airField1.DirectionX = $randomXDirection;

cheers,

Pete


#3

This doesn’t work. I think I’m incorrectly addressing the attributes. Does anyone have a MEL API or know where I can find one?


#4

To purely answer your question above that expression did not work because you are missing a “$” sign in front of “randomXDirection” variable.


#5

Thanks, I’m new to MEL and didn’t realize that.


#6

Wouldn’t that be a value between 0 and 2?


#7

Wouldn’t that be a value between 0 and 2?

Fleabay is right; noise seems to return a value between -1 and 1.

so to get something between 1-2 :


(noise(time) + 1  ) / 2 +1 

/risto


#8

ohyeah is it -1 to 1?

anyways i just change the numbers until i get what i’m looking for.

Pete


#9

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.