Physical Animation: The Ultimate Starter Guide [UE4/UE5]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back to advanced animation application today we are doing a deep dive into physical animation in unreal engine now what is physical animation physical animation is kind of a midpoint between complete ragdoll physics and keyframed animation that's it goodbye see ya physical animation is used in video games such as grand theft auto 4 and 5 red dead redemption 2 games like totally accurate battle simulator more kind of simulation games like xenoma and vr extravaganzas like blade and sorcery use it to a very questionable effect let's take grand theft auto or red edge redemption for example when you hit someone with a car or a horse they kind of go into this half ragdoll state where they're still physically reacting to you know their surroundings they bump their head on the curb or a rock or something and you can see it you know actually hit it but they're still animated they're still trying to you know put their arm out to break their fall or they're kind of curling up in a ball or they're just flailing around like crazy it can also be used for things like hit reactions let's say i have an animation of my character like holding a weapon like this and then i also have one holding a different weapon like this and i have all of these different animations and poses and stuff but i don't want to have to keyframe hit reactions for every single one of them you know like left right backwards forwards in the gut in the back for every single one of these it just balloons out of control really rapidly what we could do instead is actually half simulate the body of the character when they get hit and the physical animation will do everything for us we can also use physical animation to simulate things like a character being tired or being like rabid like a zombie or something where we can kind of relax the the muscles of a character and still have them do an animation or at least attempt to do an animation so you know we could say this character their [Music] right arm is injured and so we're gonna set its physical animation properties to be you know at a particular strength level and it's gonna be simulated but trying to do the animation that we're giving it and that would result in let's say they were trying to do a punch or something it would kind of look really floppy and like they can't really hold up the weight of their own arm so that's another way that we can use physical animation really effectively so without any further ado let's get stuck straight into it oh sorry i was i was watching a a course about public speaking and delivery skills on skillshare who coincidentally happen to be the sponsor of today's video let's face it you are watching my video for one reason you want to learn how to make a great game if you are an aspiring indie games developer you need to know and i'm saying you need to know how to make videos making videos is probably one of the only ways that you can really communicate and start building an audience so i've personally been going through alex lyon's course communication skills become more clear concise and confident you can probably tell by my voice that i've actually started employing some of his techniques skillshare would be the perfect place to learn video production so making your own youtube videos devlogs showcasing your game to the world and all of the classes available through skillshare are kind of like my videos except they actually put effort into them so they're very easy to watch very easy to learn from very nice to look at so do both of us a massive solid and get your free month of skillshare in the description below okay so how do we set up physical animation well what we will do is we will right click our library whatever this bar is called content browser we're going to create a new blueprint class and that is going to be an actor component this is a component that gets attached to an actor it doesn't exist in the world it's just a little bundle of code that we're going to be using on a character now the reason i like to do this we're just going to call this tutorial physical anim comp whatever the reason i like to do it this way is because you can then have all of your physical animation related stuff in this little bundle of code and you can put it on characters that need it you can not put it on characters that don't need it it just makes it a lot easier to manage rather than put all this code in your base character class and literally everything from then on inherits that code when it doesn't need to the other nice thing is that whenever you're doing you know an interaction with something let's say something takes damage you can just use the get component by class function uh and then we can actually just look for tutorial physical anim comp and then do something of the component if it finds one now this component is completely blank so what we're going to do is on beginplay we're going to add component by class we're going to add it to the owner of this component that we're creating and the class is physical animation component now this is the unreal physical animation component and this is as its name suggests a component that handles physical animation but since we want to add our own functionality we're going to create this component at runtime and store its reference as a variable and then the last thing that we need to do is we need to actually set a skeletal mesh or a skeletal mesh as we say in my area that the physical animation component is going to use so what we're going to do is we're going to get the owner we're going to get component by class or alternatively if you have a character class or something that you use um you can go cast to i use my own class called living being we could just chuck this here if we wanted i actually do this cast usually in like a parent component and we can say as living being get mesh since this is derived from the character class and we can just plug that in there bam compile one extra thing we will actually want to do is get this mesh and we want to promote it to a variable so let's just put that there and now our physical animation component is set up and ready to be used it's as simple as that so first up let's just create an event custom event this one is called uh let's call this a toggle physical animation what we're going to do when we toggle physical animation we will need the mesh component itself and the physical animation component we're going to simulate bodies below simulate physics the in bone name we're going to make literal name and we're going to type pelvis and then what we aren't going to do is tick include self because we want to simulate everything but the pelvis the pelvis 99 of the time you want the pelvis to be not simulated because it is kind of the the anchor point of the character if it was to simulate then the character would literally just fall to the ground and they wouldn't move along with you know the character movement component or anything like that we're going to click new simulate tick so let's just take this little bit that we've done so far let's go to our player character i'm just going to go keyboard r just very hacky way of you know doing debug letters and whatnot we're going to add the component tutorial physical animcomp we're going to drag that into here and then we're going to call the toggle physical animation function when we press r fantastic okay so let's see what happens if i am running around with my beautiful character here and i press r it's going to completely simulate there is no physical animation going on here yet this is just purely a rag doll this might be what you're going for but i highly doubt it so what we want to do instead is actually apply physical animation profile below from the physical animation component the body name is pelvis not pelleves pelvis the profile name is something that we're going to set up shortly after this little section now i already have one set up called hit reaction profile we are not going to include self uh clear not found if true bodies without a given profile name will have any existing physical animation settings cleared if false bodies without the given profile name are left untouched i think we want to keep that false fantastic now if we go back in and we hit r you can see that now my character is kind of ragdolling they're kind of flopping about they look really tired this is like me before two o'clock in the afternoon every day this is what i look like and you can see that the running animation is still happening except it's kind of half ragdolled and if i go into combat mode and i start punching you can see my character is really really struggling to uh hit anything effectively so this is physical animation at a base level so we've got we've got we've got animation and we've got oh this is gonna work we've got physical simulation oh what the am i doing and then they combine to make physical animation it's awesome so let's just take a quick look at some of the other settings that we'll be using in this component to do you know whatever we want to do there is in the physical animation component a function called set strength multiplier so if we set the strength to be zero then we're fully we're fully flopped up if we set this to be a hundred times whatever it you know whatever our profile was then you can see that well it doesn't really okay what the is going on here then you can see that it is uh doing some real whack oh my lord now the reason it's doing whack is because i'm over driving the motors to the extreme it just doesn't like it so but this can be really useful if you just need a little bit more push out of you know your your profile although we will look at some of the weaknesses of using this uh namely that you can't specify from a particular bone chain for this to be you know set to it's it's a global strength multiplier the main thing i use this for is to exit physical animation so as we're exiting physical animation i'll drive this up to like 10 or something so that it can blend out smoothly the other setting that is crucial to physical animation being useful is set all bodies below physics blend weight or you could just do set all bodies this one kind of a bit more flexible so if we make a literal name like literally make a name this is pelvis we can now set the physics blend weight zero being there is no physics blended one being there is it's fully physics now really important thing to note and this can be kind of hard to grasp this is very different to the the set strength like you might think oh this is fully physically simulated and this is not fully physically simulated like what's the difference so let's just say we put this at 0.5 and we don't apply any physical you know animation profile below so this is going to be fully floppy ragdoll mode but we're only going to blend 0.5 of that amount so if we hit play and we ragdoll you can see that this character is kind of see how there's like these weird motions where the arms are kind of flopping about all over the place really weird it isn't like half simulated if that makes sense this is still fully simulated but it's just halfway between the animation and you know the fully simulated whatever's going on the only thing that we want to use the blend weight for or the better way to think of it is like the alpha of a lerp between the keyframed animation and simulated you know ragged or whatever the only thing we want to use this for is entering and exiting our physical animation state so let's say our character gets hit in the back of the head and you know they're kind of dazed and they're like flopping around like this for a bit and we're still running if we were to just set you know stop simulating bones it would just snap immediately to this position again and it would look absolutely terrible so what we can do towards the end of our hit reaction or our physical animation state is quickly lurk from 1 through 0.5 to 0 and it will smoothly transition and then once we reach 0 that's when we say okay we're not simulating anymore you know whatever whatever now actually turning off physical animation is quite important because this can be quite expensive when you do it on mass you know like if you had every single character and all of them were you know doing physical animation simulating whatever whatever all at the same time things could get a little bit messy so when you're not using physical animation you'll want to turn it off you'll want to set simulate bodies on the mesh to false so that is a very brief overview of how to set up a physical animation component why we put it in its own little you know component that spawns a component and also what the main functions that we're going to be calling are so the next thing that we're going to cover is setting up a physics asset now if you're using the default you know unreal mannequin it'll have a physics asset already ready to go some of the constraints might not be perfect so you know just reference this video if you want to tweak them but even with that physics asset already set up for you you will need to set up a physical animation profile so when we import a skeleton for the first time or a new character or whatever it will automatically generate a physics asset this is a physics asset basically what this is is the simple collision for a skelly mesh so you can see each kind of bubble here these are like capsules um very easy to compute collision for these are all assigned to one bone each and you can see some of them are a little bit too buffy by default and it's basically going to be our job to fix them up uh if we hit simulate here you can see that you know it does function it does work and if we shift right click we can you know drag this around we can throw it around see what it's doing so you might be thinking well that seemed to you know ragdoll properly what's what's the big deal what what needs to be done to it well if we look a bit closer you can see that when this fella flops onto the floor there's gonna be like gaps here because this big pelvis collider uh is too big basically and also if you're doing any mesh accurate collision for your characters so you know you want to know oh my character got hit in the arm or something rather than you know just hitting the capsule basically any game that isn't you know a kind of hack and slash rts type thing then you will want these to be as accurate as they can be how do we do this well we can simply click on these and by using the keys w e and r just like in the in the you know editor window we can actually just scale these um by dragging we're just gonna go through here and i'm gonna tidy up these so that they are all appropriate sizes keep in mind that you can have bodies overlapping with one another because later on we can specify which bodies can collide with which other bodies so we can say this shin shouldn't collide with the foot or this one but the shin should collide with you know the chest and the arms and all that kind of stuff now this one here spine03 this one's a bit of a nightmare uh we're just gonna fix it up as well make all its rotations snapped to the nearest 90 degrees uh it's also not in the middle so if we go to the center of it this is actually the center relative to the bone that it's representing if you want to snap something to the center just set this back to zero uh it looks like spine1 didn't actually receive a a capsule by default so what we're going to do we're going to go up to options we can go to show all bones go to spine01 we're going to add replace bodies and this is going to automatically constrain this to the adjacent bones so that's just a very handy little tool to add a bone that didn't get generated automatically now of course you don't actually need a collider for every single bone i just find it handy because if we have more colliders we can actually get more bone names from our hit results so when a when a line trace or a collision hits a scaly mesh there's actually an option to get the hit bone name and that hit bone name actually comes from this physics asset so you know one thing that you'll notice if you've ever done like collisions and stuff is that you know you'll never get a collision that'll say oh i hit bone you know finger pinky bone number three or something it's always just hand and that's because usually we don't give fingers their own individual colliders because that would be very expensive um it also just leads to more jank and whatnot i guess if you're doing like a vr game or vr application or something then giving the fingers individual colliders might be something that you would do but for you know 99 of projects uh you would just give the hand a you know its own collider and when we actually look at this you can see that this collider here is assigned to the hand so any bones beyond that will just be completely stiff they'll just be following whatever the keyed animation is doing now there's a lot of stuff going on here there's a big thing and there's no big thing over here this is the clavicle which is actually worth doing a collider for i'm also going to delete the entirety of that arm over there because what we can do let me just get this chest bone shrink you in a little bit yeah that's good enough uh what we can do is we can actually mirror these dooblydoos so if we right click on this we can go mirror and it's going to add that exact size and position over here it's also going to add the constraints over here that's why i've just deleted one half of it so we can focus on this side one thing that i'm going to do with the hand i'm actually going to go to right click add shape add box and then delete the capsule usually i'll do this for the feet as well but i haven't done it yet in this case cool and now i'm going to flatten this out this way and that should be just about enough right and then i'm going to get the clavicle and we're going to add replace body add slash replace body and i rotate this to how i want it so this is our shoulders basically now the reason i put the shoulders in here is because the shoulders are actually i know it kind of doesn't seem like it but shoulders are actually like one of the the key parts of getting like natural movement these actually move like a ton more than you would really give them credit for doing my exercise um so when it comes to actually ragdolling or physical animation you know if these weren't able to move then a character that's ragdolling wouldn't actually be able to put their arms above their head like this because when you do this you're actually moving your clavicle all the way up vertically if you were to try and keep this still you can't actually get past here any any arm movement above this point above this angle is clavicle movement let's see this chest bit here okay this one definitely needs to come out a bit keep in mind this is like an actual historically shaped breastplate so the character's body is actually like here so you know i might want to make a different physics asset for when this type of armor is being worn where it has you know a bigger chest or something just so the collisions are more accurate okay so to finish up this we're going to click on our clavicle our upper arm lower arm and a hand then we're going to right click them and click mirror and i also went ahead and deleted one side of the leg and also replaced the foot with a with a cube so we're going to do the same thing here select them all mirror and that's our i guess basis of a physics asset now if you hit simulate then you can see this guy just flops down and you know physics physics wow uh what we might do is go to character go to bones and show selected only just to kind of get rid of them because they're annoying so this next part here is where things get really interesting uh aka frustrating and that is setting up the constraints for these these physics bodies if we like generated a new shape or whatever um it's gonna have an omnidirectional joint by default so if i let's say over here if i just click this bone and then simulate selected so that's going to simulate whatever we selected and anything below it you can see that this hand joint just you know if i left click it yeah you can see that it you can see that it is like free flowing uh it's got absolutely no constraint to it it is just doing its thing it can bend in any direction as far as it wants and it can also twist in any direction uh you know whichever direction it wants and that's because it's using this omnidirectional uh it's like a ball joint basically what we want to do is set all of these to limited and so this is going to if i just simulate this one you can see that it has a limit on how far it can twist around so twist would be this direction like this way as you can see the hand actually doesn't have much twist to it so it is always good to um it's a good practice to actually get your body and kind of measure how much you know things can twist individually so obviously as a fellow human being i can twist my hand around like this um but most of that comes from the the arm shin this this one the arm shin but it's always a good idea to let the constraints go a little further than they should basically a good starting point is just to set every bone to limited in every direction and we can just you know set this to limited uh and then we can just click on all these and mirror them and that will fix it on this side yeah very good very good good to do you and your good something merry mercena and i'm just going to set this to limited so if we select let's just say spine1 and we go simulate bodies below then you can see that we have simulation [Applause] now what we're gonna do is we are going to set this so that it has semi-realistic constraints a little a little rule of thumb uh like my kind of starting values are 25 25 and 10 for the twist uh this kind of just seems to work you know decent in most cases at least as a starting point okay so as we're setting up these damned constraints we want this to be able to you know reach up here but we don't want it to be able to go back this way now in order to rotate a constraint you need to hold down alt and then rotate it and you can see here that this point here now has a different uh there's two red lines basically why doesn't it just do this by default i have no clue it's just it's just a thing just remember whenever you rotate a constraint make sure you hold down the alt key otherwise this will not work so so what we'll do we'll actually just get the twist and the other bits and we'll just we'll just do this we'll test this out uh that's bloody terrifying but if we now alt drag this like this you can see that it now stops when it gets to this point and it's going to allow it to go all the way forward here so remember hold alt and we do this and we might give it a little bit of extra room here uh just for safety you know and then as we drag it up here that looks just about how it should so that's how you rotate a constraint and this is really important for things like you know elbows and also for you know the knees alright so i've finished tweaking all of this stuff it's all as good as it's gonna get and i'm just gonna i've deleted the other arms and legs and whatever and i'm just gonna mirror them now another really good way to continue testing your rag doll is actually go to physics and go gravity scale zero and if we click on the pelvis hit simulate then you can see that this fella is you know in zero gravity and this is a really good way to see whether there are any completely unnatural poses so for example i can see that these legs are actually going back too far um here this thigh is just going crazy what the hell so a little issue that i came across is sometimes when you're mirroring the bodies uh one of them will actually be well just straight up not correct now this seems to only happen when you're mirroring something that is connected to a body and the thing that you know the mirror version of it is also connected to that same body so to me it happened up here as well with the clavicles uh joining to spine three so all we need to do to fix this is make sure that we're 90 degree snapping up here and also make sure that we're rotating in world space and then we're just going to hold alt and we're going to rotate this 180 degrees and now okay that was the wrong axis oops uh okay 180 degrees that was also the wrong axis well last last time is the charming time the red axis there we go now they're perfectly together [Music] and my cats are fighting one another cats can you be quiet i'm trying to do a video all right so my physics asset is set up i'm not gonna wait for yours to be set up now if i hit simulate that looks pretty damn good to me if i do if i does say so myself now what is next is to set up the collisions so the self collisions basically all you need to do is click on a body and you can see anything that is gray when you have a body selected is something that it isn't going to collide with but anything that is blue is something that it is going to collide with so if we hit the hand here you can see the hand is colliding with nothing so if i was to do this then you'll see that i can actually move this hand you know inside and around our character however if i click on the hand and i shift click on the leg and right click on the body and we go collision enable collision now you can see that this is blue so if i hit simulate now then you can see that the hand is now colliding with the the thigh uh one thing that you don't want to do is make two things that are overlapping collide with one another because this will result in well i mean as well to show you yeah some some really wacky uh jiggling because these two bodies are within one another and they're also trying to penetrate from one another uh over and over but then the constraints are pulling them back in and it's just a never-ending battle of the penetration don't do that what i would suggest is selecting all bodies and disabling collision on all of them click on the hand collision enable collision all and then disable collision with the you know the arm and stuff that we don't want it to collide with so i'm just going to click this one we're going to click collision enable all and then collision disable that one so now if we simulate this arm the hand will collide with everything which is pretty important um i'm going to do the same with the forearms then i'm also going to do the same with the feet and the shins so i'm just about finished here but one thing i'm going to do is make every second body piece collide with one another the reason i'm doing this is to prevent uh like really tight squishing so if we enable collision here and i've just enabled it here and we select the spine one and the the other bits there you can see that because this is really kind of stretched back this collider here is now colliding with this looks good feels good is good now that we have our physics asset set up and rigged and constrained and all that good stuff the next part of this is going to be setting up our physical animation profile so in this corner down here we are going to we're going to select everything we're going to hit new and the current profile we're going to call this i'm going to call this strong the reason i'm going to call this strong is because we're going to use this for our hit reactions and stuff where we don't necessarily want the character to be flopping around too much but we still want them to be able to you know get affected by physics and and whatnot so i'm going to assign all of the selected i want the the foot as well i'm going to assign all of these to the profile strong and now you can see here where it says physical animation we have these options so we have our is local simulation check box we have orientation strength angular velocity strength position strength velocity strength max linear force max angular force blah blah blah blah blah there we go if we hit simulate uh nothing's changed and that's because we need to actually tell this hey like what strength values does this profile have so let's just select everything and into orientation strength let's just put a thousand and we'll put a thousand into angular velocity strength then if we hit simulate you can see that this fella is trying to maintain that position so what we could do if our hands and stuff are kind of where we want them to be um we could just you know adjust the the spine constraints to be more powerful so now our fella is standing upright and i can still you know push him around we could hit him we could do what we want you can actually go to physics poke where's poke poke strength i'm gonna put this up to like five thousand and if we hold control and left click then we we we poke him uh so this is this might be what a you know a hit reaction looks like if he got hit in the face or something so another thing let me just go through here and reset all of these back to zero one thing to note is this position strength value this will only work same with the velocity strength uh these will only work if this is not a local simulation so local stimulation means each bone is simulating relative to its parent bone so you know this one is trying to maintain this rotation relative to this bone here whereas if this is unticked i'm going to untick it on the hand then this is actually going to be trying to reach the position that it would be in the animation regardless of what its parent bones are doing so if i set this to 10 000 and we simulate here you can see that this hand is trying to maintain that position that it's supposed to be in regardless of what these bones are doing and this can help prevent things from flopping too much so you know like our issue before where the head is kind of flopping back too much if we made this non-local and put the position strength up to like 10 000 or something then when we simulate the head will be pulling all of this stuff up to that point you know so maybe we'll put this down to like 1 000 and we hit simulate and yeah you can kind of see that this head is acting like a almost like a helium balloon in a way uh and the rest of the body's just getting dragged along with it however this can get really janky when you're doing like ragdoll physics so you want to like knock a character over and you want them to kind of flop on the ground this will give you a very bad time so you could make a second profile uh so we could get you know select everything new profile this one could be called the ragdoll profile and we assign everything to that one and we could just simply give the head a local simulation in this profile and then in our physical animation component that we set up where it says set uh profile from bone below body something something we would just say okay well when we enter ragdoll we're going to use the ragdoll profile for all bodies and that would fix that issue so you can you know set up multiple profiles and it is recommended to set up multiple profiles for different things so if you do want to use that that world space you know kind of have the the ends of the appendages drag the rest of it along uh that would be the way that you do it come here hello my girl looks like girl cat has joined us for the rest of the video now we can go to preview animation and we can actually do this but then i'm going to select these and we're going to hit simulate and preview animation we're gonna switch to here this is our walk animation uh and it's being simulated obviously ignore the feet uh they're bound to be a little bit weird because the friction and that kind of stuff but this is kind of holding pose decently well um if we go to a run animation then you can see you know he's kind of chugging along a little bit uh it's not perfect but it's you know there's some resemblance there this would be perfect for you know a drunk character or something so it is important to test the simulation with animations as well god who needs to motion capture break dancing when you can just do this [Music] let him go bust a move all right so that is our physics asset set up ready to go we know how to make a profile we've done all the constraints we've set up all of the you know the forces and stuff that they use to blah blah blah blah blah it is time to put some of what we've been working on into practice yeah all right let's do it so first thing we're going to do is a hit reaction let's just go to him and in here we're going to give him our tutorial physical anim component very cool and in this component that we made just before i'm going to have to find mine there it is physical and component tutorial thingo [Music] what we want to do is get our tick function uh we're also going to make sure that our component isn't ticking by default we're going to have an event called uh hit reaction we've made a custom event called hit reaction it needs an input of hit result uh let's just call this hit very cool this goes down to there so what we do when this happens is we set the component to start ticking and we increment the hit reaction time remaining uh this isn't actually time necessarily this is just a value that goes up like we set it upwards and then it will lerp back down towards zero over time then what we're going to do is we're going to apply a physical animation profile below pelvis not including self then we're going to set all bodies below simulate physics new simulate yes simulate then what we're going to do is we're going to add an impulse after we've set this to simulate physics now little thing that i do um is if the hit hits the pelvis then hit the spine instead this is just a little thing to prevent warnings that can pop up if you hit the pelvis and it wasn't simulating there would be a little warning uh not an error or anything just a warning saying this would need to be simulating physics if you want to add impulse blah blah blah blah very cool so the impulse needs a bone name so we're getting the bone name from the hit result that we're going to be passing into this hit reaction event and it needs an impulse which is a velocity so it's a direction and magnitude of that direction the way we're getting this is we're getting the trace start and the trace end and minusing the start from the end that's going to give us the distance or sorry not the distance but the vector between the start and the end of the trace then we're going to normalize that which is going to get that same direction and make it a magnitude of 1. then we're going to multiply that by big number this is like your this is your strength value of the of the hit or something you could base this off whatever variable you want and then we're going to add impulse and then on tick what we're going to do is we are going to set on tick the hit reaction time remaining towards zero we're also gonna minus this small number from it that's just so it actually reaches zero at some point otherwise it would just tend towards zero and never actually reach it after this is done we actually check is this less than or equal to zero if it is equal to zero we know that the hit reaction has finished so we're gonna set the value to zero just for safety then we set all bodies below simulate physics to false and then we stop the component ticking very cool however if this isn't true what we're going to do is we're going to set the blend weight to whatever the hit reaction time remaining is you know this might be at like two and then it will come down to one and this will still be like fully simulated whatever whatever and then as it approaches that last little stretch that last bit from one to zero it will lurk back the blend weight or the alpha between fully simulated and not simulated at all uh it would just lurk that back to you know the original position that it should be in due to the animation so this is just there to you know exit from the physical animation without any like stuttering or anything so what we can do now i'm just going to go to literally anything um i might just get a projectile or something when it hits something all i'm going to do is we're just going to get whatever it hit i'm going to say cast to oh actually no get component by class we're going to look for tutorial physics anim comp and we're just gonna call the hit reaction function or event same thing uh and then into the hit we're just gonna plug whatever the hit of this line trace is this could be a line trace this could be uh like an overlap or like a hit result or something it could just be you know whatever you want it to be so if we go here we're gonna press p i'm printing on the side here what the like remaining value for the hit reaction is so you can see as it goes from zero to one he actually lerps back to his original position like that uh and so you can see that the blend between physics and not physics is seamless there's no like jerking or anything you could use like a an s-curve function to smooth this out a bit more it's probably something that i'll do um and the reason that i like doing it this way is that you can keep adding to it while it's in the middle of happening rather than a timeline which would reset every time you hit it and look really janky this is the way i like to do it uh you can also kind of differentiate between different like hits with this so like if they got like really hit in the face with a hammer or something you could just say bam add like five seconds or whatever and it would look like they're kind of dazed and and all that kind of stuff all right the second little example that we're going to be looking at is having a character ragdoll but then self-preserved so put their arms out in front of them or put their elbows out behind them if they're falling over backwards currently i don't have this set up on this character i'm not going to be going over how to like exit ragdoll smoothly like this it's just it's a little bit too out of scope for this video i only have limited time i am happy to go over how to you know exit ragdoll smoothly like this i just use the method that is in the als free uh what is it locomotion system thingo if you just dive into that study you know try and dig through the absolute monolithic and mbp in that session and try and find out where the ragdoll stuff is you can basically just kind of copy that one for one and get pretty good results so what we need in order for this to work basically we need an enter ragdoll function um that's part of my action system we set tick enabled we're gonna set a boolean is ragdoll to be true then we apply a physical animation profile below set the movement mode to none just so we can't override the movement of the ragdoll and stuff we also set the collision of the capsule to false or no collision and then we set all bodies below simulate physics including including the pelvis that's important just as a safeguard we also set the physics blend weight to one so it's fully physically simulated uh just because this might have been a different value because of the hit reaction and stuff and then basically on tick from that point uh all we need to do is get the socket rotation of the pelvis uh in the x direction so this is the ragdoll pelvis roll and the other thing that you'll need is the ragdoll's distance from the ground and you know you can do this with a line trace however you want i'm not going to hold your hand through literally everything in your life what we want to do now is in our and in blueprint we are going to have in our anim graph sorry near the very end of our anim graph like literally right right before we go into the output pose we're going to have a blind poses by bull is ragdolling is the bullion and into the true pose we are going to have a blend space called ragdolling preservation poses now on this we will need to set the ragdoll pelvis direction and the distance from the ground this blend space looks like when we're above 400 units from the ground it looks just like a mid-air flailing animation but then if we're close to the ground a hundred units from the ground it will look like this if we're falling backwards this if we're falling forwards and you know sideways or something if we're falling sideways very cool so i'm just quickly going to get a reference to i'm going to get the prismatica physical animation component this is my one i prepared earlier and then all we need to do is promote this to a variable this is called physical animation component hit compile we're gonna go back to our thingo we're gonna use property access we're going to go to physical animation component because we just got a reference to it before we're going to get the ragdoll pelvis roll bam and we're going to do the same thing here physical animation component we're going to get the ragdoll distance from ground and plug them in fantastic and now when we're in the ragdolling state uh it's gonna be doing this animation and because we're doing physical animation it's going to actually you know physically simulate it so if we are running and we ragdoll then our character if they fall forward will put their hands out in front of them if we fall backwards they will put their arms out behind them i know that's not safe falling practice but uh i know neither of these actually a safe falling practice but it's kind of just instinctually what people would do um so yeah we can keep doing this you can see that it always does the right thing uh that looked a bit painful but you know again uh and then you know even if we're up in the air he'll still put his hands out in front of him um if we like i don't know for yeah follow backwards you can see it it just works it just works now if we were to be really high up in the air and we ragdoll you'll see that it'll do this flailing animation and then at the very last second uh if he had time he would have put his arms out in front of him luckily they survived the fall because we need them for one more demonstration lastly but not leastly um we're basically just gonna do a repeat of what we did at the very start of the video so let's just do another event called tired state all we're gonna do here is set a animation profile below then we are going to set all bodies simulate physics and then we are going to set the blend weight to some value now what you would want to do in this case is you actually want to get this strength multiplier this is this is probably one of the only places i would use this strength multiplier so you would want your animation profile to be pretty strong to begin with so you know you'd want it to be i don't know maybe in the 5000s or something so that the animation basically looks exactly how it should if as if it was keyframed um and then all you would need to do is get your you know health component or stamina component or whatever you wanted to use to drive this thing and any time that you updated it you would call this event and you would have some variable that would be like i don't know some some math formula maybe it would be like current stamina divided by max stamina and that would be the strength multiplier so one being they're fully just you know doing their thing and then zero being they're like completely flopping around 0.5 would mean they're they're pretty tired so i'm just gonna go keyboard uh cue and we are just going to call the tired state here do that compile and now if i press q we alright i did something really really bad uh we don't want to include self and we don't want to include self and we don't want to include self here either okay so let's do this again if we hit q now you can see that this character is yeah when we when we start and stop moving they're kind of wobbling around a bit um this is like really subtle so this could be just as they're kind of beginning to get a bit tired uh if they do a roll they're going to be kind of flopping a bit bit funky if we move back and forth you can see it kind of flopping um if we were to let's say run out of stamina or you know run out of stamina even more then maybe it would you know start to look like this where it's like really kind of floppy uh looks like they can't keep themselves upright at all really and the nice thing about this is that it affects all animations from this point so if i like do some sword swings you can see that they look really really uh tired as well all right that sums up the three use cases that i said that we would go through um i guess that is the physical animation unreal engine thing i think all that's left for me to do now is to edit this video and see if there was anything that i missed and if there isn't anything that i missed then thank you very much for watching and as i mentioned earlier in the video the first 1000 people to click the link in the description can get one month free of skillshare and you can learn whatever you want i would recommend learning video production i know that lily singh has a really good course on making youtube videos that would be really applicable to devlogs and that kind of stuff you know creating a story how to present it how to kind of market it and share it with everyone um so that's just another one that i recommend checking out lastly but not leastly discord twitch youtube no we're on youtube patreon links in description thank you very much and with that i say goodbye [Music] goodbye [Music] [Applause] [Music] you
Info
Channel: PrismaticaDev
Views: 125,231
Rating: undefined out of 5
Keywords: ue4 physics, ue4 physics animation, ue4 physics constraint, ue4 procedural animation, ue4 physical animation, ue4 physical animation hit, unreal engine, unreal engine 5 physics, unreal engine 5 physics simulation, unreal engine 5 physics tutorial, ue5 tutorial, unreal engine animation tutorial, unreal engine animation blueprint, ue4 animation blueprint, ue4 animation montage, ue4 hit reaction tutorial, ue4 hit reaction physics, ue4 hit reaction animation, ue4, ue5, game physics
Id: 46NfgXlnCzM
Channel Id: undefined
Length: 57min 10sec (3430 seconds)
Published: Sat Feb 19 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.