Skill Level Intermediate
- [George] Hi, I'm George Maestri, and today we're going to take a look at MASH. We're going to us MASH and the Flight node to create this simulation of moths circling a light. So, this looks like a lot of fun. So, let's go ahead and get started. We're going to start off with a scene called Moth_Light.ma, and it has this light bulb here, plus three moths. Actually, it only has one moth and two blend shapes. So, the first thing we have to do is actually animate the moth, and we're going to do that using blend shapes.
So, I'm going to select these two moths and then select this one last. And then, if we go into Deform, we should be able to find the Blend Shape node, and let's go ahead and add that. And when we do that, you'll see that in the Attribute Editor we have a blend shape for this moth. And, so, you can see how I can move him up or down. So, let's go ahead and do a quick animation. I'm going to start in the up position.
So, I'm going to move that all the way up, right-click, Set Key, and then set a key on the down one as well. I'm going to move two frames forward to frame three, and then we're going to zero everything out and again set keys for both. And then I'm going to go to frame five and bring up the down blend shape. So, now we have one flap of his wings. Now, in order to make him flap continuously, we need to do a little bit of a trick in the Graph Editor.
So, I'm going to go into Windows, Animation Editors, Graph Editor, and you'll see we already have the shapes here. So, all I have to do is just select those, and under Curves, Post Infinity, we want to do Oscillate. And now that little guy flaps his wings into the night. So, let's go ahead and select the blend shapes and hide them by hitting Control + H. Okay, so now we're ready to set up our MASH network.
So, I'm going to select my moth, and under MASH I'm going to say Create MASH Network. Now, we have some options here, and one of the ones I want to look at here is this Distribution Type. I'm going to go ahead and distribute this along a grid, and that'll just space them apart a little bit better for the effect. So, I'm going to ahead and hit Apply and Close. And now we've got a grid full of moths. And, if we go into the Attribute Editor, you'll see we have a Distribute node, and you can see that this is distributing along a grid.
Right now we have 10 moths, and that should be enough. So, from this MASH network we can now start to add in modifiers to start to create the effect. Now, the first thing I want to do is I want to get them moving a little bit more noisily. So, I'm going to add in the Signal node. Now, this used to be called a Noise node, but it's actually called now a Signal node because it can also do things such as, trigonometry and stuff, but we're going to keep this on 4D Noise.
And then I want to animate the position equally in all the dimensions, so I'm just going to go ahead and put four into each one of X, Y, and Z. Now, when we do that, you can see how they're kind of just, they're a little bit more random. So, now we've got these guys kind of moving a little bit more random. And let's go back to the MASH1 node, and now let's add in our Flight node. So, when I do that, all sorts of things happen.
This big, giant object comes up. And, if I hit play, you can see that they're all kind of flyin' around. But they're really flying in just kind of a random direction. We're really not attracting them to the light bulb. So, what we need to do is create an attractor that they can fly towards. Now, I don't want this to be the light bulb, because they don't really want to hit the light bulb. So, I'm going to make an object around the light bulb that they can flock to.
And then we'll go ahead and make the light bulb a repellent so that they won't hit that light bulb. So, actually, I'm going to go into my top view here. Let's go ahead and create a sphere, and I'm going to scale this up. I'm want to scale it bigger than that light bulb, and I'm going to move it up so that it's pretty much centered on the light bulb as well.
So, there we go. Now, this is going to be what's called an attractor. So, the moths are going to fly towards that sphere, and we're going to hide that a little bit later so that way it won't interfere with the scene. So, I want to go into my Outliner. Make sure I have that up, 'cause we need to start working from the Outliner here. And I'm going to go ahead and select this big colored object here which is my Flight node. In fact, you can see it here in the Outliner, this MASH_Flight node. And it's a little tight here on this screen, but if you notice here we've got all sorts of values here.
We have Separation Strength. We have the Main Controls here. We've got Speed and Mass. We've got Gravitate and Inertia, but the one I'm looking for down here is called Attractor Controls. And what that is is the thing that attracts the flock. So, we need to add an object as an attractor, and that's going to be that Sphere1. So, I need to select my Flight node. Now, this is a little bit tricky. It's kind of a little outside standard Maya workflow, but you just hover over the sphere that you just created, middle-click and drag over that box, and let go.
And there we go. So, now these are all going to start flocking towards that sphere. Pretty cool, huh? Let's go ahead and set this up so we can see what's going on. So, I'm going to go ahead and select this sphere. Let's go into the Channel box, and under Layers I'm going to just do Create Layer from Selected, and then we'll just leave it at that. And then I'll template that so we can see it, but it's not really in the scene. In fact, I'm going to go ahead and scale this up just a little bit. I want this a little bit bigger, somewhere around there.
So, let's go ahead and play, and as you can see, they're attracted to that attractor. But we want to make sure that they don't fly into that light bulb. We can make that light bulb repel the moths so that way they don't fly into it. So, I'm going to go back into my Attribute Editor, and right below Attractor Controls we have Obstacle Controls. So, I want to make sure my Outliner is up, and then I want to say Connect Obstacle Mesh. When I do, it says, Please select a mesh.
I'm going to hover over LightBulb in the Outliner and left-click on it, and it should be selected. So, let's go back to Flight node here. And now we've got an Avoidance Type of Flee, and then we can turn up the Obstacle Strength. So, it's going to repel by this number, and it's going to attract by this number. So, we've got two numbers, Attraction Strength and Obstacle Strength. So, I'm going to turn down my Attraction Strength to about four, and let's just go ahead and play it.
So, as you can see, we're starting to get a pretty good effect here, but we can still manipulate this a little bit. So, one of the things we want to do is affect the speed of this. So, we have a minimum and a maximum speed. I'm going to make these fly a little bit slower, so I'm going to turn this down to about three or so and then maybe make my minimum speed about .5, so that way they have kind of a narrower range of speed. And then you can see how these are starting to flock. Now, the other thing I can do is I can start to make sure that they're all flying in the same orientation.
Right now they're kind of just floppin' all over the place. So, we can do that by adding an orient node. So, I'm going to keep this all selected, go over to my MASH1 tab, and under Orient I'm going to add an Orient node. So, one of the things we need to do is we need to change this. If we keep it at Aim at Target, notice how they kind of just get stuck there. So, I'm going to turn this to Velocity, and that'll kind of orient them according to their velocity.
But then we also need to change their Up Vector. Notice how they're kind of sitting vertically, so I'm going to change this to X, and that should change it. And then we can also turn on Smooth Rotations to make this a little bit more realistic. So, as you can see, this is starting to work out pretty well. So, we've created a flocking behavior. It's attracted to the object around the light, and then the light itself repels the moths.
So, hopefully this gives you a little bit of an insight as to how you can do flocking behavior in MASH.