Animations
You can't have a static sprite moving over the screen. Here is the setup for 4-direction movement. However, 2-direction movement is also included in here with how to flip the sprite on the X-axis.
Last updated
You can't have a static sprite moving over the screen. Here is the setup for 4-direction movement. However, 2-direction movement is also included in here with how to flip the sprite on the X-axis.
Last updated
In the scene, drag one of the sprites. Make sure it is selected before you start creating animations so you can see it in the scene.
Once the window is open, click "Create" and then save the first animation file. Then, drag and drop the sprites from the project folder and into the timeline. You'll be able to drag multiple at the same time and even scale them all with the blue handles on each side.
Note: The last frame needs to have a second copy of it at the end about 10 seconds later so that the animation loops properly.
In the opposite side animation, simply add the "Sprite Renderer" -> Flip X, and then make sure it only has one key frame and that it is checked. Now, for that entire animation, the sprite is flipped.
This is where we can have this one sprite have many different animations and transition seamlessly between them. Open the Animator window.
If the Player Sprite gameObject is selected in the scene view, this is what you should see.
The orange animation means that is set as the default.
To create a transition, right click on the box, select "Create Transition" and then pull that arrow to the box you want to transition it to. Clicking on the line between the two animations will bring up the Transition details in the "Inspector" panel.
"Has Exit Time" allows you to play a certain animation for a set time before it automatically goes to the next animation.
"Transition Duration" means how long will the transition last before it goes to the next animation. In this use case, we want to transition to happen immediately, so this field is set to 0.
To add parameters that will trigger transitions, you can do so in this place.
For this use case, individually setting transitions between all states is going to be messy. We're going to use a Blend Tree. Delete all the other animation blocks except for the default. Right click on an empty space in the animator window, click "Create State," and select "From New Blend Tree."
Double-clicking on the blend tree box will let you go into it.
Very useful button for animation. Note the circle.
This opens the animations library.
Note: Make sure that there is an "Animator" component on the gameObject holding the sprites and that it has the correct animator controller asset.
Create a second blend tree for the idle animation. Add two more floats to parameters.
Set the animation default to the idle blend tree. You're going to create four individual transitions from idle to movement, and in each condition, set one of the variables.
Greater than 0.1, Less than -0.1; moveX, moveY
Transitioning back to idle from movement requires only one transition.