Chain gun in Maya tutorial E-mail
Written by Dzordz   
Thursday, 21 December 2006
Article Index
Chain gun in Maya tutorial
Page 2
Page 3

Then go to animation mode, select locator and the group and go to constraints/aim constraint option box. Set aim axis to the direction your gun is pointing at (in my case it was Z), and set only on X axis. This way gun will aim only up and down.

 

 

Image

 

 

 

Image

 

 

Then locator and select upper part group (turret), constraint them to Y axis.

 

 

Image

 

 

 

That way if you move locator up only gun will move, but if you move it to the side, turret will move also.

 

 

Image

 

 

Then you can go to attribute editor and change rotation limits, so gun couldn’t penetrate into lower parts of turret, and also it couldn’t aim to high.

 

 

Image

 

 

Now rigging. Select locator, and in channels menu at the bottom choose add attribute. This will pop up a window. Name the new attribute Firing, and set type to float, min to 0 and max to 10. This attribute will control firing rate of the gun.

 

 

Image

 

 

Then also in the channels menu, go to expressions. This will open expression editor. Fear not! This is simpler than it looks. Enter this code:

 

    If (Aim_Locator.Firing>0) {

       Gun.rotateZ+=Aim_Locator.Firing*10;

    };

 

This means that if Firing attribute is greater than 0 rotate gun around its Z axis (spin the gun), and multiply that by 10 (to get faster rotation).

 

 

Image

 

 

Then create some simple Nurbs geometry, this will be nozzle streak

 

 

Image

 

 

Assign surfaceShader to it, assign ramp like this one to its glow color attribute, and lower transparency and color to 0 (black).

 

 

Image

 

 

Duplicate the streak and group five streaks together. For streak group (I call it nozzles), create expression:

 

Nozzles.rotateZ=rand(0,360);

 

This means that nozzles will rotate randomly every frame of animation.

 

 

Image

 

 

Then group them again and align them to center axis of a gun (you might need to create locator to help you find that axis), duplicate group with duplicate input graph checked, which means that expression will be copied also. Rotate every new group for 60 degrees.

 

 

Image

 

 

 

Image

 

 

 

Image

 

 

Parent nozzles to the gun, so they will rotate with the gun.

 

 

Image

 

 

If you render you will get something like this. Now only thing left is to make nozzles appear only when firing attribute is greater than 0.

 

 

Image

 

 

To do that select the nozzles group (parent of all nozzles), and create expression like this:

 

If (Aim_Locator.Firing>0) {

NozzlesGroup.visibility=1;

}

else

{

NozzlesGroup.visibility=0;

};

 

which means that nozzles will be visible if Firing is greater than 0 and in every other case (that means less or equal to 0) it will not be visible.

 

 

Image

 

 

So that’s it, I hope this helped you to understand basics of MEL expressions in Maya

 

 

Image

 

 

 

Image

 

 



 
< Prev   Next >