Why Animation Curves In Unity Are So Useful

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] curves are everywhere we see them in nature we see them in physics and of course we see them in our animations and when it comes to animations curves are the way forward curves give movement more natural weight so they're frequently used because straight linear movements feel janky and weird but it's not just animations that can be improved by curves you see i am a firm believer that if you're struggling to make something feel good or your game's numbers feel off the fix is probably just an animation curve away hi there i'm matt and welcome to game dev guide [Music] in this video we're going to look at some alternative ways that we can use animation curves when developing a game in unity before we get started i'd like to give a quick shout out to the gamedev guide patreon if you're a regular viewer and have been enjoying these videos please do consider becoming a patron by heading over to patreon.com gamedev guide or clicking the link in the description below there's currently three tiers available starting from just one dollar a month and anyone that signs up gets access to an exclusive patreon only channel in the game dev guide discord now let's take a look at one of the fun things we can do with curves so the obvious and most conventional use case for an animation curve is to influence the movement of keyframes within an animation if you've messed around in timeline or recorded animations in the animator you'll likely be pretty familiar with how animation curves work as a quick refresh though here are the common types of animation curve that we might want to use to add a little bit more character to anything we want to move you see linear movement is often quite boring and frequently defines the laws of physics animation curves allow us to introduce a sense of weight to the things we're trying to move and make the movements feel more [Music] realistic with this in mind we can consider how an animation curve can be used to introduce a sense of easing to any movement we want to create in our game i've already spoken in a previous video about how we can control animations using a tweening library and most tweening libraries will support the use of custom animation curves to control the weight of our coded animations however animation curves aren't just for fixed animations we can also use them to tune more advanced movements let's suppose that i'm working on a platformer and i'd like my character controller to accelerate a bit before reaching their max velocity traditionally we may just use a linear acceleration method where the speed increases by a fixed rate until we hit a max value but as mentioned before that's really boring the alternative most folks might use is to look up some algorithm to create a nice curved movement for acceleration but then tuning the various values and looking up all the different algorithms on wall from alpha can be pretty time consuming instead we can use animation curves to take away that frustration and have a visual tunable control right inside of the editor here i've added an animation curve called movement curve in my code whenever i want to move i sample the curve with the amount of time the move button has been held down for and use the return value as my speed the animation curve is currently linear so it doesn't look any different than before however if i start making adjustments here you can see that my character now accelerates based on the curve and that i can adjust the time it takes for the player to reach maximum velocity [Music] as you can see mathematical functions that would often take multiple lines of code are much more easily achieved by simply sampling an animation curve you can use a similar function for speed gravity pushback drag cornering and more in a similar vein we can use an animation curve to ease out some of our more traditional movements for instance remember the camera controller from this video well we can use an animation curve to adjust how our camera moves from point a to point b we can use the curves to adjust the ease of both the zoom and rotation to make the camera move much more smoothly and we can more easily experiment with different settings to change how that movement feels [Music] in the previous examples we focused mostly on types of movements of objects but we're not limited to using curves just for movement or animation we really can use them on any kind of value that we'd like to transform one of the most effective use cases that i've found for animation curves is to transform progression values in a non-linear fashion curves are great for managing any kind of stat or number that rely on player progression or experience levels let's take a look at what i mean by this so here i have a class with different variables for a player's stats in my rpg as they gain experience i want the player to level up but i don't want the amount of experience they have to earn to increase linearly per level because as i've said before that's boring design and doesn't feel good early on i want the experience required to increase gradually and then as the player gets further into the game require more and more experience before leveling up so we can do this by sampling a curve with the current amount of experience points the player has and determine their current level i want the maximum level to be 100 so i'll make my first point at zero and then my second at 100. i'll then set the maximum experience points they need to earn to reach this to 100 000. in my code i'll pass the player's current level into the graph and retrieve the amount of experience for that level i'll then sample the next level to get the experience they need and subtract their current amount of experience giving me the remaining amount they'll need to level up i can then use these values to show their current progress on a progress bar let's also build a custom editor class and print each step out in the inspector we'll iterate through all of our levels sample the curve and pop the return value in a label wrapping it neatly up into a scroll view in a similar way we can also adjust the balance of the stats that are influenced by the level we can make some tabs in our editor to change the currently viewed readout one of the benefits of building an editor like this and using curves is that it makes balancing stats figures much much easier i can make a change to my curve and the editor instantly shows me all of the tiers and their corresponding values obviously some play testing will need to occur but i can much more easily eyeball values that i think will work beforehand and finally the most literal use of an animation curve is to well draw a curve you see much like everything else discussed in the video we can actually plot the coordinates of our curve into a line renderer by sampling at a different point in time allowing us to draw curves in the editor and get the corresponding curve on screen in our game using the line renderer or in our ui so these are just a few examples of the alternative ways we can use animation curves i'm sure there are many more use cases you can think of so feel free to let me know yours below that's it for today's video before i go i'd like to give a quick thanks to this video sponsor skillshare as you know by now skillshare is an online learning community with thousands of inspiring classes to choose from skillshare helps you explore new skills deepen existing passions and get lost in creativity whether you're interested in improving your storytelling mastering your artistic talents or brushing up on your business and marketing there's tons you can learn and apply back into your game development journey and because skillshare is a platform specifically curated for learning there are no ads and they are always adding new premium classes so you can stay focused and go wherever your creativity takes you if you're interested in skillshare and you want to help support the channel the first 1000 of you to click the link in the description below we'll get access to a one month free trial of skillshare's premium membership allowing you to explore your creativity and check out some of these classes for yourself if you've enjoyed the video be sure to hit the thumbs up button and let me know your thoughts down below if you're new to the channel please consider subscribing as you'll get access to new videos when they go live alternatively if you'd like to see more from me first you can click the link on screen now to check out another video as always thank you very much for watching and i will see you again next time
Info
Channel: Game Dev Guide
Views: 19,040
Rating: undefined out of 5
Keywords: unity, learn, games, gamedev, how to, making games in unity, tutorial, unity tutorial, learning unity, unity3d tutorial, programming, making games
Id: Nc9x0LfvJhI
Channel Id: undefined
Length: 7min 39sec (459 seconds)
Published: Fri Oct 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.