Creating Simple Animations (Unity Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today we're going to look at how we can create simple animations in unity we'll add an animation to the collectibles in this scene to make them spin and move up and down okay we're going to start with this scene that has a character that can run around and collect diamonds we've covered how to create this scene in the earlier videos of our 3d platformer series so take a look if you want to know how it was done alternatively you can download this project by supporting us on patreon all the relevant links can be found in the description at the moment the diamonds are completely static we're going to create an animation to make them look a bit more interesting let's select one of the diamonds in the hierarchy then we'll select window animation animation this will open the animation window to begin animating we need to click create to create an animation clip we'll navigate to the animations folder and name the animation clip diamond idle now we can start creating the animation the first thing we need to do is add the properties we want to animate we'll click add property then we'll expand the child gem object and add the rotation most of the time you're going to want to animate a child object so that any changes made by the animation are done in local space so for example we wouldn't want to set the parent diamond's position in an animation as this would cause all the diamonds in the scene to be set to the same position changing the position of the child object is okay though as it will always be relative to the parent we now have the rotation property and a keyframe at the start and end of the animation keyframes allow us to set property values at certain times in the animation and then unity will calculate all the values in between so we have the rotation starting at zero we'll then click this button to go to the next keyframe we want to have the diamond spin all the way around so we'll set the y value to 360. if we press play now we can see the diamond spin it's not looking great at the moment though first of all it's moving far too fast let's stop the animation and increase the duration we can use the mouse wheel to zoom out on this view we'll zoom out until we can see the 10 second marker then we'll hold down the left mouse button on the keyframe and drag it to around the 10 second point now when we press play it's rotating much slower you'll notice that the diamond slows down to a complete stop towards the end of the animation before starting the next spin ideally we want it to spin at a constant speed to understand why it's behaving the way it is we need to switch to the curves tab here we can see the animation curve it starts off slow before speeding up then it slows down again at the end this type of smooth movement is often what we want which is why it's the default curve we can change this to be whatever we want though in this case we want it to be linear we can do this by selecting the y value on the left hand panel then we'll right click the first keyframe and select both tangents linear we'll do the same for the last keyframe now you can see we have a straight line and the values should change at a constant rate let's play the clip to check this now the diamond spins at a constant rate the next thing we're going to do is have the diamond move up and down slightly we'll switch back to the dope sheet and add another property this time we'll add the position of the gem we want the diamond to start and end at the original position so we can leave the start and end keyframes as they are we're going to add in some additional keyframes to move it up and down we'll click on the timeline about two and a half seconds in the easiest way to add a new keyframe is to press the record button this will record any changes we make in the inspector let's increase the y position to 0.5 you can see it's now added a keyframe with this value we'll add another one in around the 5 second mark this time we'll set it back to 0.4 finally we'll add another at the seven and a half second mark and we'll set this one to 0.5 now we'll turn off record mode and press play the diamond now moves up and down this time the default animation curve looks good with the movement slowing down when reaching the top and bottom that completes the creation of the animation the final thing left to do is apply this animation to all the diamonds in the scene let's close the animation window and click on the diamond in the hierarchy we can see that this diamond now has an animator assigned if we double click this we can see that the entry state is the diamond idle animation this means that when the game starts the animation we have created will play as the diamond is a prefab we can easily apply these changes to all the diamonds we'll click back on it in the hierarchy then we just need to click on overrides apply all let's press play to try this out now all the diamonds spin and move up and down this type of simple animation can really help draw the player's attention to items of interest in your game okay that covers everything for this video a big thank you to all our patrons we really appreciate you helping to support the channel if you'd like to help and also get access to the source code you can find details in the description please leave any questions or feedback in the comments and subscribe and click the bell icon so you don't miss the next one thanks guys
Info
Channel: Ketra Games
Views: 100,335
Rating: undefined out of 5
Keywords: Animation Unity, Create Animation Unity, Create Animation Clip Unity, Add Keyframe Unity, Animator Unity, Animation Unity 3d, Create Animation Unity 3d, Create Animation Clip Unity 3d, Animator Unity 3d, Unity, Unity Tutorial, unity3d, Unity3d Tutorial, Learn Unity, Indie Game Development, Game Development, Learn Unity3D, Unity 3d, Unity Tutorials, unity 3d Tutorial, Tutorial, Game Development Unity, Unity Game Tutorial, Unity Tutorial for Beginners, Unity Beginner Tutorial
Id: JVFg9g4f-ME
Channel Id: undefined
Length: 6min 20sec (380 seconds)
Published: Thu Feb 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.