[MUSIC] Let's go back again to the scene we're creating in VR. And this time I want to animate this door. So I've got a Door that consists of a DoorFrame, which is called door. And this DoorPivot object, which contains the door itself. And I set this up so if were to take the DoorPivot, it rotates nicely like a door. That's good, but we don't want to have to do that by hand, we want the door to open and close by itself, ideally. When we look at it or when we interact with it. So I'm going to do this through keyframe animation because it's quite easy to do by animation. So I'm going to go through that process, but we are going to look at using an animator to make it interactive. As we did in the previous examples when I looked at keyframe animation for the first time, we created an asset which is going to be an animation, call that DoorOpen. And I'm going to create a second animation, which is called DoorClose. And I'm also going to create an animated controller, which is, I'm going to call DoorInteraction. Now you might want to go back and look at my original lectures on keyframe animation if you want to revise any of this. But the DoorInteraction, the animated controller, that is the thing that's going to contain the state machines. And when we first looked at animations, we already created the state machines, but we didn't really think of the much, much, we just used it to trigger animation. This time we're going to really look at how to use that animator control. So first off I'm going to add a component which is an animator and I'm going to select that door into action animator as the animator for this door object. I'm not putting it on the DoorPivot, I'm putting it on the main door, putting it on the main object you don't have to have it on the actual object that's moving, you can have it on sub-object. So I'd prefer to put the animator on the object that's really the thing in itself. So they're not a sub-object. Now, the animator is currently empty, so let's put some animations in there. Let's do DoorOpen. And DoorClose. And I'm actually going to do something else, which is, To create an empty state, which doesn't have an animation attached to it. So if I select that in the spare time, give it name. And I'm going to make that the default state. So why am I doing that? Well, I don't want the door to do anything when we start up, we just want it to do nothing. Now, so I'm going to now actually create some animations. So I've now selected DoorOpen and what we need to do here is just hit Record and select the DoorPivot. And I don't really want to do anything there. But rotate it a tiny bit to set a keyframe. And I'm not going to loop it this time. So my the first time I showed you animation, I showed you how to loop it. This is going to just stay open at the end, so I'm going to put keyframe after one second, and that's going to be a keyframe with the door being open. Okay, so it's going to go from one state where the door's closed to another state the door being open. So that's the door open animation, which will open the door. Let's look at the other animation we want, which is DoorClose. Select that and here we have it, it's an empty animation. And what I want to do is actually select the same animations from DoorOpen and copy them onto DoorClosed. So now commonly it's the same animation, it will open the door, but I actually want to reverse them. So I'm going to drag, deselect the other one, I'm going to drag them so they swap places. So the DoorOpen which is the end of the other animation is now the start point of the first. So they go naturally from one to the other. DoorOpen opens the door and it ends in the open state, DoorClose closes the door and it ends in the closed state. And you can do one and then the other. And that's what we want to set up with the animator. So what we want to do is create some transitions. Now, let's start by the most basic transition, is from Empty we can make a transition, we right click, we make transitions like DoorOpen. There is now a transition from Empty to DoorOpen. Now, the most important thing is that these transitions happen on a certain condition. And so we want to find when they happen. And to do that we're going to set up a parameter. So a parameter is basically something in the animator that can trigger various actions. So with a complex animator you're going to have lots of parameters, because lots of things can happen. I'm just going to create one, which is a trigger. And I'm just going to call that Door. And what that does is that it is going to either trigger closing the door if the door is open, or if the door is already closed we're going to trigger opening it. So let's have a look at this transition. We can see that various things I'm going to remove Has exit time. Basically that means it can happen at any time. And I'm going to add a condition down here. And the condition is going to be Door. That's all it needs basically whenever the door happens it's going to transition to the DoorOpen state. So let's have a look in the game, here, if I click Door, it's going to open, fantastic. So we got a transition from Empty to DoorOpen. So that's what a state machine does, it controls when you go from one animation to another. Then I create another transition to DoorClose, and DoorOpen to DoorClose. Again, that's going to be based on Door, and back the other way, again, based on Door. So if we play this we can see that when I click door it opens. When I click it again it closes. Click it again it opens. That's what we wanted to do, great. Now, all that we need to add is some interaction. And I'm going to add a few components, which are part of my, Of the VR Interactive. The VR Interactive Item. And then I'm going to go to my, VR Action Harness. So these are the two things that you really need, VR Interactive Item means that it will respond to your interactions. VR Interaction Harness is the things I've set up so that it'll respond events as I want. And which I talked about in the previous video. And then the last component is going to be the VR Interactive Animation. And that's the thing that's going to trigger the state machine. Now, you don't need to set up the animator, because it'll automatically find it on this object, because it's on this object. But we do need the animation trigger. So the animation trigger is just this parameter here, it's just Door. So I'm going to, it's got exactly the same name, I'm going to use the name Door. So this should be set up now so that the animations will trigger when I look at the door. So if we look at it, it's triggering that section module and it's triggered the door to open. If you look down at the states, you'll also see the states are changing. If I do it again, it'll trigger again and close the door. So there we have it, some interaction gaze-based interaction with a door, this will even work on cardboard, it's not using anything fancy. It's a really powerful technique to get some nice movements, and an interesting set of interactions for objects. So that's keyframe animation and state machines [MUSIC]