Hey, what is up, nation?
In this session I'm gonna be teaching you how you can add some dynamic properties
to your components to make them randomly rotate on click.
Alright, so I modeled this treasure chest and I put it in on these little coins
and then they were all the same because they were in the same direction.
And so I thought "hey, it'd be really cool to use a dynamic component
to then be able to click on these and get a random rotation!".
So that it adds a little bit of variety in here instead of going through and manually rotating each coin.
So what I did is I made this is a dynamic component, so in the top right here you can say
I have this toolbar docked. If you right-click in a open area in your toolbar
and just you want to find where it says "dynamic components", and just make sure that's checked.
When it's checked originally, it'll show a little window.
And then you can just drag that into an open area and that will dock that into your toolbar.
So we're gonna be using today, interact with dynamic components this little hand here
is what we use to start to interact on click.
And then what we're gonna be using is component attributes, because that's
where all the magic happens, that's down here.
And what you can see here, just to talk about what is going on, by default,
there's some rotation in here that I have brought in, that just shows where the rotation is.
Here is my command for unclick, and then I have these custom parameters: ranX, ranY and ranZ.
So basically an overview of what happens here is that on click I set ranX, ranY, and ranZ
to a random number, between I changed it a little bit because originally I had from 0 to 360.
That being the amount of degrees in a circle for all of these.
But what I realized is that I kind of wanted these coins to lay flat.
I didn't actually want it to be 360, because I don't want a vertical coin.
so I messed around with some of the angles as I was going through.
And doing this have changed some of them.
I figured Z, which is the blue. And a good way to just sort of think about this as you go through,
is just like as you can see these are color-coded, so when you're in your component,
you just want to make sure use your cue to enable the rotate tool.
And just check and make sure that the angles that you're using are what you want.
And you can use the colors to sorta - I guess guide you through that.
So what I've done here is I've gone through and I've taken my coin, and I've removed all of the attributes from it.
So that we can really dive into this together.
So when you click on your click on your object,
make sure that you have component attributes brought up, and then it will show you this little window.
This is called the sketch link.
So and then it's made of two components, what you see nested underneath.
There both halves, they're flipped from each other.
But we won't need to really mess with these in the model.
We're just gonna use the out our most component.
So we're gonna hit this little plus thing, it's gonna allow us to add some different options.
We're gonna add all of the rotational axis.
So if you go to the top thing there you can then add all,
so we're gonna just click that, and gives this these three things.
In here, you can just change any of these to whatever you want.
So I just did that there. There's some extra options in here.
If you click this little arrow on the side where you can set from a list and things like that.
And that will add that option to your component options up here in the top right.
So when you click that, if you had this enabled you would see that option in there.
So that's where that comes from: add attribute here.
So I'm going to do on click, because we want the sketch link to do something when we click.
And then for this, we're gonna be using three random numbers.
So what I'm gonna do here is put in three custom dental fires and our custom name.
So I'm going to put in a ran X, and use the same sort of characteristics as up here.
So do that again. Just come down, enter a custom name, ranY.
And that's just random, that's why I'm choosing this.
And I'm making these up, so these could be anything you want.
So we have these few things. So now what we want to do,
is we want to set ran rotX, rotY, and wrote Z to their respective random number.
I'm gonna come up here, I'm going to double click, hit the equals.
And then you can actually shift click on the text, and we'll just bring that over.
So it's saying that there's no number in here, because we haven't generated our function yet.
Okay, in our on click what we're gonna do is say "set",
so that is saying set this parameter, I'm about to do to something.
We're gonna do a parenthesis. And the first part of set is the what you want to set.
So in here I'm gonna do in quotation marks: ranX
And then what we want, and for all these commands, you can find them on Sketchup,
I'll link down in the description where you can find all the descriptions of the commands.
We're gonna put in ran between here so the first thing is the parameter.
So ran X the second thing is the number.
So we're setting the number. But because we want this to be a random number.
We're gonna choose 1. Then you choose the range here, so ran between 0.
And then comma, and then the second number, and then we have ran in between.
And then we need to do it an extra parenthesis here on the end,
because we need to close everything out. Ao we have set. We have a parenthesis here.
Then we have our stuff here and then we just need to make sure we close that off here.
So I'm gonna hit enter, and that's just going to enable that.
And we're just gonna check and make sure this works. So that when I click to activate,
you can see down here that we get a new number in here.
And if I click again, it'll generate a new number between 0 and 25.
So you just do that. Now that's only one parameter, we have three of these.
But this code looks good, so I'm gonna do ctrl+a to just copy that, or to select all.
And then ctrl+C to copy it. But I need to add a semicolon between my commands.
So I just added a semicolon there and hit cntr+V to paste And then I just need to change my number here.
So ran Y, I'm going to change to... or change ranX to ranY there.
Another semicolon. And then control V to paste again.
And then I'm gonna change this to ran Z.
And now in this particular case, I don't necessarily need just 25.
The reason that I have chose 25.
And for the other two, is that I want this coin to be kind of flat.
That it can have a little bit of leeway in the x and y direction.
But what I really want is just a little bit of variety for it to be mostly flat.
That's why I chose from 0 to 25.
The z axis it can be rotated in any direction. I'm using 360 because that's the degrees in a circle.
It doesn't matter what that is. So it give me a little bit more variety in the Z direction.
So that looks good. I'm gonna hit enter on this.
And it's just gonna put that in.
Now when I select this, you can see that it generates new numbers for all of these.
And then puts that up here because these two things are linked.
So hopefully this helped!
If you liked this video, please don't forget to like, subscribe and share this video with your friends!
And as always, happy hacking!