Expressions to scale, rotate and spin

Tutorial posted over 3 years ago
by aziz-khanaziz-khan

Hello every one! Welcome to my Maya expression tutorial. In this tutorial I will show you how to rotate, scale, and spin your objects thorough expressions using Maya. This tutorial is very handy to create explosions ( tank explosion, asteroid explosions so on).

Step 1

Create any object you like to experiment with- in this I have created a piece of stone, as shown in the image below.

Step 2

Now go to your Dynamics module by holding down the H key and click Dynamics.

Select Create Emitter option box from the Particle drop down menu.

Step 3

Now change the following settings as shown in the image and hit the Create button.

Step 4

Since your emitter was created, move it just a bit on the Y axis like you see me do in the image below.
Then, select your object which you are going to instance then go to Particles drop down menu again and choose the option box for Instancer (Replacement).

The option box will appear for Instancer (Replacement) keep everything as default and then hit create.

Step 5

Now hit the play button- you can see the objects are emitting instead of particles and the size of objects is all the same. Since there is no rotation or spinning let’s start working on them.

Step 6

Go to the Window menu and bring up the Outliner to select the object, from the outliner window click on Particle1 to select it on the viewport.

Step 7

Now open up your Attributes editor (CTRL+A) and then scroll down to the button to find Add Dynamic Attributes when you find it just hit the General button to create new custom attributes.

In the Attributes name choose any name you like- it does not matter what you are naming it, but always keep the names close to what you are doing with it, since we are first dealing with Scale I will name it Scale_new so you can name it anything you like, if you are new to expressions I suggest you follow along with me to avoid any confusion.

Step 8

Now, if you look in Per Particle (Array) Attributes you will see a new name- the name will appear according to what name you have given in Attributes name.

Step 9

Right click in the box of Scale_new then choose Creation Expression and write the following expression:

float $anything= rand(6,3);
particleShape1.Scale_new= <<$anything,$anything,$anything,>>;

if you want to play with the size of objects you can play around with the numbers

Step 10

Scroll up to find the Instancer (Geometry Replacement) tab then on the General Options on the Scale drop down menu choose the newly created name. In this case mine is Scale_new

Step 11

Now, if you press play you will see some random sizes of objects are coming out of the emitter.

It’s time to deal with the rotation of objects. Let’s create another Custom Attribute like we did before for Scale, go to Add Dynamic Attributes tab and do the same as we did before, but the name should be different, since we are dealing with Rotation, I name it Rotation_new - go ahead and use any name you prefer.

Step 12

Now write the following expression:

particleShape1.Rotation_new= <<rand(360),rand(360),rand(360)>>;

Step 13

Now go back to Instancer (Geometry Replacement) tab in the Rotation Options choose Rotation then from drop down menu choose your custom name.

Now if you press play you will see the objects are not rotating, instead they are oriented in different directions. That's what we'll deal with next- spinning of objects.

Step 14

Last but not the least, create one more custom name for our object spin. Name it anything you prefer, but in this I have named it Rand_rotation.

Now you have to change the vector radio to Float radio since we will deal with Creation Expression and Runtime Expression.

Step 15

Add the following expression:

particleShape1.Rand_rotation= rand(-50, 40);

If you think these numbers are too high you can decrease them to any satisfactory amount

Step 16

Play your animation- you should see that there is no changing on the spinning of the objects. We will add the expression for the spinning of the objects now.

First, open up your expression editor by default the radio button is set to Creation since we will deal with Runtime Expression hit the button called runtime after dynamics and then add the following expression:

particleShape1.Rotation_new += particleShape1.Rand_rotation;

With this you will be able to spin your objects.

Hope this tutorial taught you some interesting ways to manipulate objects!

Sample Scene

You can download the scene here: Expression sample scene


  • Views 440
  • Likes 0
  • Comments 0

Share tutorial

  • Maya
  • Script
  • Expression
  • 3D
  • Animation