Animating vehicles - Tutorial request Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
before we continue with the video if you like what i'm doing here on this channel please consider subscribing it helps the channel a lot anyway let's get back to the video so this is essentially what we will be creating today we will be taking a look at how you can animate your skeletal meshes that are sort of like vehicles like the vigilante example assets or any other vehicle assets essentially and show how you can make them come alive and make the animations or have their skeletal meshes affected so that they look like they are alive and in this case we are just creating a simple rotation for our rotor here so if i press down a key you can have the rotor which will be spinning up until it gets to a max speed and i can at any point also just release the key and it will start spinning down again so that's what we will be trying to achieve today welcome in this tutorial we are going to be going through how you can make use of a vehicle for example that has a skeletal mesh and see how you can make them animate so in this particular instance we're using a vigilante asset so i'll show how it's done on that but this works on any kind of the galore object that has a skeletal mesh essentially that you want to animate if you want to understand how that works normally you would have a character and the character would have a skeleton mesh and you would have some animations and you would just make use of them in the case of this we don't need to have an animation we can animate just by having the skeletal mesh itself so in this case we have a helicopter here which is one of the showcase levels for this vigilante asset and going up here in the outliner we can open up the blueprint for this this helicopter and this helicopter is set up with a bunch of different interfaces that it can make use of this is so that it can be used as a display object for the level but it itself is inheriting from another blueprint which is called heli over here so this blueprint is the actual blueprint for the helicopter base essentially and this is what we will be making use of and looking into and manipulating a bit so hopefully you can get an understanding of how you can animate vehicles and such in this way so let's break this down into small simple components let's start off with going to our skeletal mesh over here and by clicking on the magnifying glass we can find the skeletal mesh and we can open that one up so this is our skeletal measure our mesh with our skeleton and you can see here that we have a bunch of different bones that we can make use of and how this works is essentially each of these bones if we were to click on something here you can see we have the ability to manipulate and for certain vehicles in this case the helicopter it makes sense for certain bones to do certain types of manipulations more than others if we were to click on the rotor main jnt here for example it is the bone that corresponds to the main rotor around here on the helicopter and in this case if we were to say rotate this bone around the z-axis you can see that we get a rotation for the rotor itself and this is how we can make use of the bones to animate something because we have all of these bones available to us we have complete liberty to use any of them in any way that we want to it can be for most part it will be rotations like changing the turrets or turning up wheels and things like that but there could be some things that actually actually just move in a local space instead of rotating but in this case we will be focusing a bit on on the rotation parts so we will essentially be making some code that allows this to happen so that we have the helicopter animating in a sense where it looks like it's about to take off at first glance it might be a little bit difficult to see which ones of these are of interest or not so what you can do is you can go to character and bones and select all hierarchy this means that it will display all the different bones that you have available to you and you can see which are the ones that are most likely going to be of interest you can see which ones are the likely ones to have a possible rotation to make it look like it it would be interacting with the real world so that's something that you can do so that's the first thing understanding that the bones are here and we can manipulate them so how does it actually do that well going back to our blueprint here let's close the one that has all the the interfaces in it and state to the the main one if we were to go yeah like this one so controls the speed of the main rotor what are we doing here we have a function which we can call at some point and we can set a variable which is called main rotor speed main rotor speed in itself is being used as an input to the anim instance and setting a variable over there called main rotor speed so what does this mean well this means that the anom instance for this object which is in this case is the skeletal mesh has a animation blueprint here and this animation blueprint we're saying set main rotor speed to something in it so if we open up this animation blueprint over here this is what it looks like so right here we can see there are some things for stabilizer turrets flap wheels and wheels let's see do we have any rotors we have rotation data for wheels it says but it actually has the main rotor speed here which is the variable that was being set here main rotor speed so what is being done here well essentially we have a variable which is currently set to zero which is being multiplied by the main rotor speed which is set to zero by default this is going to be changed in run time of course and then multiplying it by a negative number and then it's saying essentially use this as the set value to set a rotator over here so this is just another variable which we have a rotation so this will be a value between 0 and 360 if you're using degrees and if you were to have a value above 360 like 720 that's essentially just 360 times two so it would be 360. so it's essentially just rotating around its axis in in complete circles now this main rotator itself we can just right click and say find references and we can see that it's being set somewhere and that is over here and we can say that it's being get somewhere else clicking here we can see where that is actually being used and this is the the updating of the animation graph where it gets its pose from if we were to go to the right here we can see here we get the output pose so here you can see we have a bunch of different um transforms of bone which is essentially what we did when we were rotating it over here with the bone but being handled in the animation script instead or animation blueprint and it's very easy to create these all you have to do is right click and you type transform bone and you get one of these notes and then you can see that it it handles an input post so you would just hook it like so and the output post you just hook to the next part in the chain if you want to have multiple ones and then you can see that you have a translation a rotation and a scale that you can set so the the rotation here is being used as the value to set what the rotation of this bone is supposed to be and this node right now is not actually linking to any specific bone if you look at these transforms you can see that it has a bone variable set here rotor move jmt which is exactly the one that we were moving around over here in our um attempt to visualize what we're trying to do and how to set one of those is you open up this node here and you can see here the bone to modify and you just pick the bone that you want to affect in some way essentially so that's how one of these is actually set up so hooking this back up again and removing this node we now should have a pretty good understanding what we're doing is we're rotating a bone and this is done by sending some kind of value to our animation blueprint which in itself is let's see over here taking that value and every every frame it is updating and saying that my so my rotation for my rotor should be something let's call it x and then that is being used over here to determine how that is actually looking on the model itself so that's the whole flow of it so how can we make use of this well let's go to our animation no not our animation our blueprint again and let's actually make this uh usable to start off we can see that this helicopter is currently inheriting from a actor you can see actor over here and if we wanted to make use of this helicopter in our game and we wanted to actually play it we needed to have it as a pawn so we can actually take control over it to do that we can go to file and read parent blueprint and we type in pawn and now we should be able to control this helicopter theoretically however in this case we have now currently the showcase mesh or blueprint for this one so what we want to do is we want to click on the blueprint that we have right here which is the parent of the showcase one and we'll say that we want to browse to it and then we while having it selected over here we want to right click on the helicopter and say replace selected actor with this helicopter so now this one will be the helicopter that we have actually made into a pawn we can see that by uh clicking on this blueprint link and it should be opening up the blueprint that we have been messing around with currently to test that this is working we want to add an event let's say keyboard one and from this we'll just drag out the print so we'll print string a hello if we press the one key and this should happen if this helicopter is being controlled by us because pawns also pick up input so taking on this helicopter again we need to type in possess you can see here i have already typed in possess earlier or pause so auto possess you want to set to player 0 and by having clear player 0 that means that if we start playing it should be automatically taken control of by our player controller so we click the selected viewport and you can see we end up under the helicopter so we now have control over it pressing the one key we can see that nothing is happening so let's check what that is all about uh if we go to our world settings we can see that we have we have a whole class called show visible this is related to the the level that is created for this and we wanted to choose the normal hud class which doesn't have anything in it because this one will likely be conflicting with us so let's click play again pressing now you can see we get our hellos here so now we have properly control over this helicopter let's create a camera for this one so we get something we can see from a different angle this will go um a boom it's not called a boom camera we want the camera and we want to have it's called spring arm action spring arm like so so we'll put the spring arm under the skeletal mesh no not like that we undo that we want to have it oh it is under the skeletal measure already that's good so we won't have the camera under the spring arm and then we can either control it with the spring arm information saying like i don't know 600 back maybe even further 800 we maybe want to position it a bit something like so and maybe have it as a an angle slightly looking downwards or something let's say we try that one so if we press play now this is what we see so you can tweak around with the variables to get something that you like but essentially now let's do some functionality that actually drives some animation that we want to create so we'll go to our blueprint again and go to the event graph the very first thing that we're gonna do is we're going to be um this event currently we'll just unhook it so that you know that it's not actually working anymore so the main rotor we shouldn't be getting your rotor speed but we'll also be going into our animation blueprint and we'll find in the event graph the update rotor speed here for the wheels and everything like that and we'll just disconnect that as well so now we don't have anything that should be updating the the main rotation because this is the only place where it's being set and we are now currently not setting any information for it to update with so we will be driving all of this functionality in our blueprint just to make this easier to grasp so let's go back here we can remove this debugging that we had and let's start making something so let us work backwards we know that if we go to our animation blueprint that if we set the main rotor rotation it's being updated here per frame but we have disconnected any functionality of it actually being set currently with disconnecting these nodes so we can actually make use of that we can say that our animation instance over here we want to update the the rotor directly now we can't do that because in our animation blueprint if we go to the main rotor rotation over here it is set as private which means that we can't access it from other uh blueprints since we're doing this they're they've done this to protect the variable from being accessed from outside but we're doing this to learn and understand how this works so we'll uncheck the private so that we will be able to have access to it going back to our blueprint now we can say set main rotation rotor or rotor rotation and you can see that we have access to this now if we right click and split the rotator we can see that these are the float values that we have to work with now how we want to do this can vary but what we will be doing is essentially we will be making a event which will work sort of as an ignition and once it started it will start to rotate and then it will rotate faster and faster until it has reached its top speed let's say to begin with we can just do something a little bit simpler just to see that it works to do that we will start off by right clicking on the zed and we'll say promote to variable and we'll say it'll get default main router rotation jaw here as the name which is perfectly fine and it will have a default value of zero which is also perfectly fine for us to begin with and we can right click and add another event keyboard let's use the one key again we can say that what we want to do is we want to take this value and we want to add a value to that one and let's say we want to add let's take 20. and then after we have done that we want to set this value so setting the main rotator to be this new value that we have just managed yet and then after that we say set in the animation instance that our main rotor rotation for z should be this value which we have now just added to so this should mean that every time we press the one key now our rotor should be rotating 20 degrees so let's play and we can see that pressing the one key does exactly that now you can see here technically this is rotating in the wrong way which is why they had the multiplier minus one because according to how the fins are it's supposed to rotate in the other direction but that's up to you to fix that if you want to this is mainly for understanding how this works so now we know that we can actually affect the rotator from outside so how would you actually go about making something like the ignition that we spoke of well we can make use of something called a timeline for example there are many other ways but adding a timeline allows us to rotate the rotation i'm going to call it and we can just say that once we press 1 it's supposed to play and what will happen inside of this one we can say we want to have a new track we can say we want to have a float track and we can say that this is the rotation uh percentage or something like that and on this one we can uh right click and add a key and then right click and add another key and we can click on the first one and say at time zero we're supposed to have a value of zero and then click on the other one and we say at time five since the length of this one is five we want to have a value of one and clicking on these two to zoom to fit we can see what that curve looks like so this will be our curve we will be going from zero to one over a period of 5 seconds everything is fine so far what we want to do is we want to make use of this value which we get out which is this percentage here and use that to drive our rotator since this will be going between zero and one and let's say that we wanted a full revolution of the rotor to be what happens once we have reached the five second mark we want to multiply this value with 360 because of 360 degrees so like so and then we could actually hook this directly into our main rotator like so and make sure that our update runs into this one and we can remove this so this means that when the timeline it gets called it will start updating it will go through this timeline and every update it will run through and update this rotation like this so let's see what that looks like so we press one and you can see that it spins around and it will do a full revolution in five seconds now and that's all good and fine as a start but it doesn't continue from there now there are many ways you can solve this in you can have a tick you can have it on a timer or you can just make use of this timeline if you wanted to and on the finish event here we could add a reroll just to make it clear what we're doing and then we can drag this to the play from start now you might be wondering why do we choose to play from start well the play will resume this timeline from wherever it is currently on it so it if it was like the rotation was partially done it would continue from the timeline and then update from that while unfinished we're essentially saying that once it has ended it should start playing from start and not from where it is because it is at the end and now it should essentially be playing the rotor multiple that's the wrong key sorry there we go sorry wrong keys all the wrong keys pressing one let's rotate okay so three quarters one revolution and it still continues to spin so now that theoretically works this is one way you can go about doing this and now you can have it as so that this is being controlled by some sort of speed as well so you can add another float here and you can see that this one is supposed to be the speed so if we promote this to a variable we can say that this is supposed to be our let's call it rotation speed this will dictate now how fast this will be running so if we have it like currently we have zero as default if you press one nothing will happen the the rotor won't start spinning at all if we instead had this as value of one we would have the rotation that we had before as 10 it would be going 10 times as fast so now it should be going 10 times faster so that's how you can manipulate that and now you might be thinking well how do i change this then well you can have this as a curve if you wanted to because this rotation that we have over here is essentially a curve going here this is a curve so this in conjunction with our speed could determine our end speed how i mean this is if this rotation speed is our maximum speed let's say so this is the amount of revolutions that we get as maximum and we're happy with that we can now make use of our sorry over here our curve over here to determine um that it should be winding up in the beginning for example uh so if we uh right click and add a curve uh a key here and we were to do something like this and drag them out so it's a little bit steeper in the end like so you can see that it should be fairly slow in the beginning until it gets to the end so let's see what that looks like now you can see that it's slow starts slowly and then it spins up and then it goes faster and faster and then it's really fast in the beginning however now you can see that we start off from the beginning again if we go back here to our timeline you can see that we're playing from start once we have finished so this is of course now being contradicting to what we want to have because once we have reached the the maximum of this curve or once it has essentially started up we don't want it to slow down in speed so let's build upon this a little bit and let's say that when we press down the one key it will start to rotate until it gets to the full speed and if we release it at any point it will stop so what we want to do here is essentially first of all we can get rid of this connection here and we can say that we instead want to promote this value here so we promote this value to let's call it percentage raw i guess something like that so we'll update the percentage throttle whenever this updates and instead we can disconnect this and say we want to move this over here and we can see that we want to update this on tick instead and we do this because it's fluid and it's going to give us a smooth animation for our rotator uh so we want to use this percentage throttle now as our value in here just like before so it will be going from zero to one and once it's reached the end here it has the the value one set and then that means that we have our full power essentially which means one times this value but we don't want to have a rotation like this now anymore now we instead want to make use of our delta seconds to see how much has it rotated since the last frame we essentially updated the problem with this is that now we have a delta done this is essentially going to give us a fixed value where it might vary a little bit depending on the delta seconds but this is essentially a delta that we want to add upon something that already exists so we want to actually get the rotator rotation from here just so we can make use of what is the last position it had so we break the rotator now we have the last cell value it had over here and we can add to this one the value that we have calculated here the delta essentially and then we can make use of that to send it in here but in addition to that we can also do something in addition and that is we can drag out from this and we can type in a percentage sign which gives us a modulus a modulus is essentially going to be making sure that everything is within the range that you give here so if we put 360 we can say that it will have a value between 0 and 359 and once it gets to 360 it will essentially start over from zero again so our calculation goes in here and we will always have a value between 0 and 359 which will represent our degrees on this essentially now since we're using delta seconds here this will be a very low value and won't actually spin that fast i believe let's actually give it a try and see what happens so i press the key and it's just barely moving you can see so let's try a higher value let's try something like 3000 and let's see what that looks like looks like press one and it starts off and it builds up speed until it has a very high speed so this is the max speed now for our rotor and it's fine and it's working as an ignition which speeds up but let's say we wanted to have this speeding down as well now that means that we can have on our pressed uh sorry our released here we can do the reverse reverse here means that it will reverse from wherever it was so if we only held it down so it was like halfway through it will stop from the halfway through and go down towards one so let's see what this looks like i hold down one key i let go and it slows down i hold down one key and it starts spinning up and i keep holding it down and you see it spins up to the max and then it continues like that at max speed and i let go and it starts slowing down again so this is how you can approach essentially doing animations it it is a very simple example that works on pretty much everything because for a helicopter most of the things will be rotations you will have your tail rotor over here it will be spinning or rotating you have the main rotor which we have shown here you can have your gun here which could rotate upwards and downwards according to let's see this is this right angle that's not the right angle is this the right i want this bone so you could rotate the the turret and you can do the same with the wheels over here let's see if i can hit the wheels properly so you can fold them no that's that's not okay yeah anyway hopefully you get my idea here and it's and it works the same with like cockpit uh windows and stuff like that you can open these up let's see if we can get one so you can open up a window like so and you can have your different limitations like what kind of degrees you will allow it to open up to and stuff like that so essentially you can use this kind of technique to anything now this became a little bit of a more advanced example because we wanted to have some functionality for like spinning up and slowing down and this is something that you want to keep running all the time once you actually are spin spun up for the rotor unlike something like um the door which you would only like rotate with the timeline until it's done and then you're done and essentially that's it so you don't have to have it all a tick because normally i advise against using tech but this is one of the cases where you might want to have it running essentially with some limitations of course so yeah hopefully this was helpful and gave you some insight into how you can make use of the vigilante assets or other skeletal mesh assets as well keep on learning take care hopefully found this video helpful if you liked the video leave a like if you did not like it leave a dislike leave any suggestions or comments you have down below subscribe and share this video if you want to see more like it in the future that is all for now keep on learning take care [Music] you
Info
Channel: LeafBranchGames
Views: 16,923
Rating: undefined out of 5
Keywords: Unreal Engine 5, Game system, Game development, Tutorial, Create a game system, Beginner, Intermediate, Advanced, Damage, Great, Animations, Flexible, Scalable, Good practice, Base, Customizing, Use case, Basics, Awesome, Easy, Setup, APC, Vigilante, Chaos, Vehicle, Animating
Id: Z03o2IkPB98
Channel Id: undefined
Length: 30min 28sec (1828 seconds)
Published: Tue Aug 30 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.