Unity is a game development engine used to develop applications across various platforms. Among other things, it also creates Virtual Reality (VR) applications. Please visit this link to learn more about how to set up Unity for VR.
We can animate prefabs within the scene. This can be done by modifying their transform properties. To do so, we will follow the steps mentioned below:
Add an animation controller to the scene. This can be done by right-clicking inside the "Project" window and selecting "Create > Animator Controller." Name this controller "Hands".
Next, we need to add an animator component to our hand prefab. Select the prefab from the "Project" window, click "Add Component," and add an animator.
We must attach the animation controller to the animator on the hand prefab. Under the "Animator" component inside the "Inspector" window, select the "Hands" animation controller from the menu that appears after clicking the "Controller."
We can create a separate folder containing the animation controller and all the other animations to organize the animations in our project. Now we need to create the animations. Below are the steps that need to be followed to achieve this task:
Click the "Window -> Animation -> Animator". A separate window will open that can be docked at the desired place in the editor.
Double-click the hand prefab and select the hand model from the "Hierarchy" window. Inside the "Animation" window, an option will appear to create an animation. Click on it and create the animation. It will appear in the project's root directory and can be moved to the animations folder.
We need to add the properties inside the newly created animation we want to modify. Inside the "Hierarchy" window, if we expand the hand model, we can see that this particular model has
We need to use their rotation property, so we'll add it to the animation we created by clicking the "Add Property." For this particular animation, we'll need to rotate the index finger and the thumb. So we'll add the properties for those two fingers only.
Next, we'll select the last keyframe in the "Animation" window and hit the "Record" button. We'll now rotate the index finger and the thumb to the position they're supposed to acquire by the end of the animation and stop the recording.
Once the recording is complete, we can play the animation using the play button to see how it looks.
Next up, we'll modify the
Click the "Window > Animation > Animator" and create a new Blend Tree by right-clicking inside the window that opens and select "Create State -> From New Blend Tree."
When a new Blend Tree is created, double-click on it to enter its state.
Inside the left pane, click the "Parameters," delete the already created variable, and click the “+” icon to add another variable of type float.
Click the Blend Tree in the window's center and the "Inspector" window, and change its blend type to "Direct."
Now we add a new "Motion" field by clicking the "+" icon in the "Inspector" window.
In the "Motion" field, drag the animation we created earlier and choose the float variable previously created in the "Parameter" field.
The animation plays out in the bottom right corner as the float value on the blend tree is increased or decreased. If the prefab isn't visible in the bottom right window, it can be dragged from the "Project" window into the blend tree animation window. The result is as follows:
When we adjust the value of the float variable OK
, we can see that the animation is rendered differently.
Free Resources