Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now let's take a look at how to use dynamic components to create interactivity in our models. So I already have a model open that has interactivity, so let's just do a quick refresh on how interactivity works. We'll go to Tools>Interact, and if you hover over an interactive element in the scene, the little hand icon will light up. So if I click on that I can open and close this refrigerator, and notice how the vegetable drawers also open and close.
So let's go ahead and add this to a blank refrigerator, so I'm going to go ahead and open up a file here called Fridge_01, which is basically just a blank version of that refrigerator with no interactivity. So let's go ahead and start on the vegetable drawers here. So I'm going to go into my Dynamic Components>Component Attributes, and notice now we have a refrigerator which is the main component and underneath that we have several subcomponents here, one of which is the drawers, so if I double-click on this you can see I have got a Drawer_Right and a Drawer_Left.
So let's go, let's go to the Drawer_Right here, and let's go ahead and add an attribute. Now what we want to do is we want to move this along this green axis and that will slide it in and out. So we need to add an attribute for that, so I'm going to go ahead and Add attribute and we're going to position that along Y, remember green is Y, and that tells us the position that is right now.
If we want -- well, I'm going to go ahead and copy this, so I'm just going to go ahead and hit Ctrl+C or Command+C on the Mac, just so I have that number, it's 35.3125. Now I'm going to go ahead and just type in a number to see what happens. So if I type in say a big number, say 40, well that actually pushes it in. I want to go the opposite direction, so let's try 30, well 30 pulls it out. Let's try something a little bit less, let's try 20, so 20 seems to be the magic number where it kind of comes out completely.
So what I'm going to do here is I'm going to go ahead and paste in my number here so I have it. And so now I know it needs to go between this number and 20 to slide in and out. Okay, so now that I have those numbers, I'm going to go ahead and add another attribute. And the attribute I'm going to add is onClick and that is the attribute that adds interactivity to our objects. So let's go ahead and hit onClick. And now we have to put in a formula.
We have to add in the formula for what happens when we click, well what is going to happen. Let's go into a function here, and if you scroll down here you'll notice that there are a number of onClick Functions. One is Alert, which will give you a message. We have a couple of Animate ones; Fast, Slow, Custom. We can go to individual scenes, we can redraw the scene, or we can set any attribute we want. In this case we're going to want animate, so let's go ahead and select Animate and that just brings it up here, so we need to insert it.
So we're going to animate an attribute or what attribute that we're animating, well we're animating Y. So let's go ahead and animate Y, and state1 is going to be that number that we had, which was 35.3125, and then second state is where the drawer is completely pulled out, which is 20 inches. So we're going to animate between 35 and 20 along Y. Now if we want we could actually add in more numbers, so if we wanted to go halfway out and then all the way out we could do it that way as well, but let's just do it this way.
So if we hit Enter that should make it work. So let's go ahead and go to tools> Interact, and yes it's lighting up and so now I can pull out and push in the drawer. Great! So let's go ahead and do the same for the second drawer. So I'm going to go ahead and add my attribute, and Again, position in Y, and notice how this number is exactly the same. So it acts pretty much the same formula, so all we have to do now is add an attribute for onClick and because this number is the same all we have to do is just copy and paste the formula that we created before, so I'm going to go and do Ctrl+C or Command+C, go into here and do a Ctrl+V or Command+V, and so now I have interactivity on both of these drawers.
So let's go ahead into that, and let's interact and there we go, very cool. So as you can see we use the onClick function to add interactivity, and then we have a number of things that we can do once we've added that and those are defined by the onClick Functions, and in this case we used Animate just to animate the drawers along the Y axis.
Get unlimited access to all courses for just $25/month.Become a member
100 Video lessons · 11044 Viewers
56 Video lessons · 9836 Viewers
83 Video lessons · 7765 Viewers
97 Video lessons · 5787 Viewers