Procedural Animation: Tail, Wings, Hair, Tentacles! (Unity Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this video is sponsored by my friend thomas brush and his course full-time game dev get a massive 40 discount using the link in the description welcome back to black thorn prod in this video we'll learn how to create stylish wiggly creatures using c sharp and the line renderer component inside unity this can be used to create a variety of interesting characters for example you'll be able to create snakes which slither around the scene the art style will be completely up to you or perhaps love craftian monsters with elegant tentacles this makes for stylish animated movements without a single keyframe or animation clip being made it all works with player inputs and some code i learned this from owen senior a fellow indie game developer and winner of the blank thorn prod game jam and gmtk game jam he's made a variety of incredibly juicy and interesting worlds i highly recommend you play his games which are almost all free and they're fun and inspiring while doing so you'll notice some wiggly creatures all made using these simple techniques i'm about to share so thank you owen for this knowledge let's all put it to good use let's start by creating this little monster first of all we need a head so i'll drag and drop this head sprite into my empty unity scene now i'll try and get this head rotating to face my mouse cursor i'll create a c-sharp script called rotate to target and open the app inside visual studio this is the chunk of code i'll be using if you want the head to face something other than the cursor you would simply need to change this tiny piece of code to a different transform or vector 2. i'll save the script and add it to my header i'll set the rotation speed to something like 20 and you'll notice the head rotates to face the cursor if it doesn't try tweaking the head sprite so it faces right for more detail on how this rotation code works i have a great tutorial from another gamedev youtuber linked in the description with that done let's get the head moving towards the mouse cursor this is super easy i'll make a vector to cursor post variable and set that equal to the cursor's current coordinates then i'll use the classic transform.movetowards function this function needs three parameters the current position target position and how fast it moves from one to the other so we'll type transform.position and then cursor pose since we want to go from our current position to the cursor's position and i'll make a public float move speed variable which i'll plug in there without forgetting to multiply it with time dot delta time set a move speed value in the inspector and it should all work fine now we get down to the seriously fun stuff tentacle creation i'll make an empty game object called tentacle one move it so it's right next to the head and parent it to the creature's head then i'll add a line render component for this first example this component will have a big impact on how the tentacle looks you can always tweak these settings later but for now let's set two different positions so we can actually see the line i'll add a simple sprite default material so we lose the magenta color you can set end cap vertices to one to round off the tips of the line you can change the color and opacity right here and the thickness of the tentacle using this graph note that you can add points to both the color gradient and size graph so if for example you wanted a weird tentacle which alternates between thick and thin you can add a bunch of points and place them so it resembles a roller coaster the higher the point the thicker line now i'll make a script called tentacle and drag and drop it onto my tentacle one game object again this is owen's script and invention so make sure to thank him in the comments let's begin with a public float tentacle length variable this will dictate how long and detailed each tentacle or trail is then we want a reference to the line renderer component i'll set the line rend position counts to be equal to length if we had only two positions then we wouldn't be able to get much smooth slither like motion with five or more it all becomes a lot more possible i'll then make an array of vector threes called segment pauses and i will also set the size of this array to be equal to the length value now i want each point in my line renderer to smoothly follow the previous points first of all i'll make a public transform target dur variable we'll drag and drop an empty game object parented to the tentacle inside of that in just a moment and so we want the first point in our vector3 array to be equal to the head position so we have the first point sorted out but what about the others well let's make a for loop that will run until i is greater than tentacle length we'll also make sure i starts at one since the first element in the array which has an index of zero has already been dealt with up here so for each other elements in the array we want to smoothly move it towards the previous point point one follows point zero point two follows point one and so on we can use the smooth damn function which gradually changes a vector towards a desired goal over time this way we get that smooth follow through motion where the tip of the tentacle is the last bits to move so let's type vector3.smooth and begin by adding the point's current position and for the second parameter is the previous point in the array we'll also add target or right multiplied by a target distance variable which i'll create up here this makes sure that the points don't all bunch up but keep a certain distance away which is especially key when the creature is static we also need a new vector 3 array for the smooth damp functions velocity which i'll make up here and set its size equal to length finally i'll make a smooth speed variable to plug in here for the last parameter this is how fast the point will reach its targets the smaller the value the faster for more info on the smoothdem function you can check out unity's documentation so let's move on and finalize this little script by setting the line renderer points positions to be equal to the coordinates of the segment pause array i'll save this and jump back into unity let's make an empty game object parented to the tentacle called target dirt make sure the red arrow points in this direction i'll then drag that inside this empty slot i'll set length equal to 30 target distance to 0.2 and smooth speeds to something really small as well like perhaps 0.05 or 0.02 will do the trick and clicking play you'll see i have a stylish tentacle for simplicity's sake you can leave the end of this smooth damp function with just the smooth speed value but if you don't mind making an extra variable called trail speed and adding an i divided by trail speed at the end here then you'll get a slightly nicer results i'll type 350 for that new value in the inspector you can then duplicate the tentacle and change the target door rotation a little bit to several wiggly bits and bulbs following the creature i have the line renderer of each tentacle set to a black color and i quite like giving each a transparent tip so it seems to smoothly fade out so have fun experiment with that for a little and then we can add some extra wiggly movement to the tentacles by making two floor variables wiggle speed and wiggle magnitude as well as a transform wiggler and then typing this in the update function you can read more on math.sinewave via unity's documentation now we need to parents the target dir to a new empty game object called wiggled which i'll place right on top of target dur and drag and drop wiggleder inside this empty slot in the inspector then i'll set wiggle speed to 10 and magnitude to 20. speed dictates how fast magnitude influences how pronounced each wavelike motion of the tentacle is so those are some other settings to play around with for extra customization of your creatures procedural tentacle-like animation from a visuals point of view let's say you wanted to customize your tail tentacle wing or hair further something more than changing color opacity and thickness well i've gone ahead for this example and made a weird tail sprite in photoshop i'll import that into unity and then create a new material this will be an unlit transparent material i'll drag and drop these sprites in there and then change the material inside of my line renderer from sprite's defaults to the new material i've just created and when i press play you'll notice these sprites bends warps and wiggles to match the line renderer the possibilities for stylish creatures and characters are practically endless now what if you wanted the tentacles to be a lot less stretchy currently when the creature stops moving slows down or speeds up the tentacles will grow longer or shorter let's create a small variation of this script that is best used for snakes worms dragons any creature that wishes to retain its form and curvature when static or when it changes speed let's create a new script called tentacle two which replaces the first three just made i'll copy the contents of the tentacle script and paste them in here i'll remove the trail speed variable and then remove this smooth damp line of code replacing it by these two here we're calculating the target pose by adding to the previous points the distance between it and the current point normalized so that the values between zero and one and finally multiplying with target distance so again points don't all bunch up in other words here we have point one it detects the direction towards the point zero as well has the distance and moves towards it along that direction pausing when it reaches target distance same for 0.2 2.1 and so on it will all become clear and easy in just a moment i'll copy all the settings shown here onto this component and then remove the tentacle script again target distance dictates how far apart each point on the line render is from the previous one whereas smooth speed will act on how fast the tentacle comes to a halt for example with a smooth speed value of 0.2 you'll notice the tentacle still takes a little bit of time to completely stop after the head itself however if we decrease this to something like 0.001 the whole tentacle feels a lot more snappy and responsive so play around with that this allows for a nice variety what's awesome is that you don't need to limit yourself to only line renderers for visuals for example say i wanted a spiky ball at the tip of my character's tail i'll drag and drop one in the scene and head into my script i'll make a public transform variable called tail end and set the position of that equal to the position of the last element in my vector 2 segment pose array i'll drag and drop the spikey ball in the inspector and as you can see it follows the tip we can take this even further by making for example several body parts each one should follow a certain element in the segment pose array so i'll make a transform array called body parts and set each body parts transform equal to the corresponding vector 2. the reason i do minus one here is because my array starts at zero but this i value is set to one now i can drag and drop all those body parts in the inspector and you'll see we get a stylish results you may very well want each body part to rotate and face the previous body parts you can easily do so by making a body rotation script that looks like this add that to every body part and drag and drop in the inspector the correct parts so for example on body part one you'll drag and drop the head for targets on part two you can drag and drop part one for part three drag and drop part two and so on this is a basic example where each body part looks the same but there's no reason not to go wild and create fascinating creatures you can have the tip look different from the middle just by changing these sprites visuals look at these elegant wings i made simply using this feather sprite you'll probably notice that your character looks a little weird when starting out all his body parts bunched up at a position of zero on x and y so i recommend you call a reset pause function in start or awake in this function you simply loop through all your tails points and add some distance between them so they aren't glued together when the game starts hopefully you can see how satisfying and easy this trail creation is experimentation is key here so don't give up too quickly if you don't get the right results with a little pushing and prodding you'll be able to create very satisfying creatures hair tails tentacles dragons whatever this video is sponsored by indie developer and youtuber thomas brush he's been making indie games for pretty much every platform for the last decades including his latest game never song on nintendo switch and steam thomas had to work extremely hard but now makes six figures a year to support his family and studio he let me try out his latest projects a comprehensive online platform called full-time game dev with over 800 students and there's just so much to learn here not only will you learn how to actually make a game from scratch but you're also going to learn how to make money with your game you'll learn about publishers crowdfunding building a personal brand marketing bundles and a strategic method to securing a slot on the steam front page there's a massive 40 discount for the first 300 students that use the link in the description and the coupon code no click below if you're interested and begin your indie game dev journey thanks for watching [Music] cheers
Info
Channel: Blackthornprod
Views: 126,346
Rating: undefined out of 5
Keywords: blackthornprod, unity, tutorial, c#, programming, art, animation, game dev, procedural animation, 2d, tentacles, hair, cloth, wings, tails, animate characters in unity, easy procedural animation, procedural animation basics, noa calice, wiggly objects, animating procedural characters, follow through motion, intro to procedural animation
Id: 9hTnlp9_wX8
Channel Id: undefined
Length: 14min 14sec (854 seconds)
Published: Sun Mar 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.