UE4 Tutorial: Realistic Plane Pawn

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back today and we're going to be making a very cool for realistic plain porn including some pitch roll your and an accurate sort of throttle system and I've just gone and edited the old biplane model that you might recognize from from my old toon shader video I've just got an added some bones here to it we got our rip bone I went for the propeller one for the rudder and one for each of the elevators at the back fins here it's all pretty well pretty simple pretty simple rig I'll put a link in the description to a place where you can download it and I've also got an export of the mannequin so we can put him in the plane as our as our little pilot okay the only thing they're going to need to do to get started is well nothing actually let's just right-click and make an e blueprint class this will be a pawn because it's a player and we'll call it fly a plane by playing pawn underscore beeping all done so let's open that up and I'll snap him up here there we go and let's add some stuff here to get our pawn all set up so let's just go add component we want to add our biplane and we don't want to use a skeletal mesh or a static West we want to use a poseable mesh so we have access to the bones here in the blueprint and we can add rotation and that kind of thing to animate the the various sort of aspects of our of our plane I'm also going to need because we can't apply physics to a poseable mesh so I'm going to need a static mesh here to be our driver pull that driver and we'll drag this onto the scene route here make it the new root of our biplane and then we'll need our usual pulling stuff like a spring attach a camera to and obviously our camera just like that so the scripted driver here we want to set our static mesh I use the 1 meter cube there we go and poseable mesh which is going to be our biplane that biplane rigged now obviously it's not going to be the best thing having this big block here in the middle of in the middle of our plane so let's set the size down to 0.1 and then grab a poseable mesh and set our size up to 10 hide our little block fed just down in the plane where no one can see it oh and it should also it was another component add another static mesh and this one would be opposed well our post mannequin is going to be our our little pilot all right normal nicely done so let's grab a spring up we'll make some changes here like set our length out we'll go let's say 800 and will also rotate it up a bit something like 15 15 ish degrees grab a camera and level that up I've been close to close to zero and we'll grab our spring up and we'll also add some lag here but not our regular camera light we just want the rotation lag and our rotational lag speed we'll start with 10 but we can tweak all of these things later on so let's get our we've got no collision on the post will mesh but our driver we need to be set as a inclusion presets we want a physics actor and we want to simulate physics make sure to check this box for simulate physics that's where the collision is set and we're ready to start building out our our blueprint of course cuz it's a player point and we have a few extra controllers let's go to project settings in the editor this one they might take a second or two to load up and down in input I've gone and added our role our role action with Q and E and I've also got throttle up and throttle down little up his left shift and thrall down is left control you can add these just by tapping this little plus here on action or axis and that should be all that all you need to do because we're gonna be piggybacking off the moveforward and moveright already existing access functions there so over here in the bio plane what do we have to do first let's make ourselves a variable we'll do the wood at the throttle first so we'll make a throttle couple throttle variables you want a boolean called throttle up hopefully I can spell properly throttle up and another one we'll call the rot all down brought all down just like that okay let's go to the event ruff yeah we get rid of all these we'll start fresh let's get our input action now we want throttle throttle up and we want our throttle down and we're going to set these bullying's based on which one of these keys is is up or down at any particular time so let's control hold him alt and drag in throttle up and throttle down and we'll duplicate both of these guys so we're throttle up pressed we want our wattle up all in to be true and when it's released set it back to false and do the same with throttle down so far so good so now whichever one of these keys is down is going to trigger one of these bullying's and affect our model so let's make a function for our model so I've got a new function here let's call it throttle bottle input and then hold in B and click for a branch we'll need so hold and ctrl and drag in our throttle up to be the condition of our first branch just plug in plug in here and we want another brush and throttle down the condition of our second one and we'll plug in he was sort of our first branch into this second branch and then we can do more things based on which ones which ones true or false as they as they appear and wanted another variable we want an integer this will be our total amount but that done make sure we set it to an integer just which we just want a whole number and we will drag this guy in just as it gets I will default value this to about 30 something fairly low we all might be taking off and landing I would be covering that in this video but add a little bit of throttle amounts so we just don't drop out of this guy as soon as we spawn in and out of the throttle amount but plus plus we'll get an increment int and then minus minus and one a decrement int this is just going to add just add one or subtract one every time these little nodes here are fired so we'll plug in our plus plus to the result about true in our first branch and a minus minus as the result of the true in our second branch and that's also clamp our integer Oh something's gone wrong you know what let's right-click and do it lamp integer minimum value zero a maximum value is 100 100 percent of throttle then plug the result of the list our integer here out of this increment into the value let's duplicate this so that we can use it in our decrement and then we just set our throttle amount based on the results of our of our coalition here so plug in the return value just in there like that the result of our increment into our set and will duplicate our set and do the same thing for our decrement all right easy enough and now just so that we can see it on screen let's get ourselves a print string and print out the result of our throttle let's duplicate these two or come up there we go so cap our bat and save and then head back to our event graph we can hook it up to our blueprint here let's grab a begin play yeah begin play it there it is and instead of going straight off the tick with our little input function it's a lot less costly on overhead if we use a set timer fire function so I'm just going to execute this once let replay the same function as frequently as we determine here in time which we'll set to 0.05 this will be the value the the speed so if you're holding in your throttle up key it's going to fire that function and increase your throttle every 0.05 seconds if you want it to do it quicker then you must make the number higher and then in function name we type in our function name which is throttle input making sure to get this exactly right if the exact title of your function otherwise this won't fire at all but that should be all that we need to do so that's all finished what's the next step let's well we'll do our a role and our pitch in your so let's just get our axis events here get an axis and access input axis role let's also get move right and also move forward there we go and we'll need another variable going forward this one will be our air control or really like how much sort of how much drag is going to be affecting the the the plane so how much how quickly is it going to be able to turn and roll and that kind of thing and we'll set this air control value and we'll compile the first so we can get to the default so to something like 2500 we'll be multiplying our air controller value here by our axis values 2 which would will be 1 or minus 1 or some some value in between so we'll get a multiplier here float multiplied by our float and I'll plug this in so if we have positive in the role will get this value of 2500 if it's negative it'll be negative 2500 so grab a driver drag this in and we'll get our forward vector either forward vector for our role the names don't quite line up but if we reoriented the pawn we could we can make the semantics work out but as it is we are just or what is the positive x that's pretty pretty common pretty standard so we'll just run with that and then from this forward vector let's multiply vector by a float multiply our air control or our access result here by our forward vector and then come out of here into our lap we'll let this vector I might make this the B value alpha here is going to be zero point one and then add torque in degrees this is going to be adding our our talk belly our roll so I plugged it in bone name doesn't have to change we'll check this box for acceleration change so that you can read the tooltip here it will be taken as a change in the angular acceleration instead of physical talk ie it's going to ignore the actual mass of our physics object and just apply the apply the force so let's grab all this stuff we're gonna copy it because we'll be using most of this for our next two axis values we'll just plug this straight in but we need to change our forward vector because we're not using the forward vector for our for our move right that's our vertical rotation around the z axis and back here what we need is the forward no the up vector sorry get up vector and this will be plugged into our multiplier and just like before let's grab all these guys duplicate once more well nothing happened I'm duplicate there we go I don't know why sometimes that bugs up and all delete this up Vector next to me what is the right vector okay it's the right vector there we go these are just the directions that a physical object is moving in any you know Eddie Eddie particular direct any particular direction any particular access that the object is operating in and that should be all that we need to do is so this will handle our basic flight controls these three history access values these calculations here this is our basic basic plane physics uh basic plain controls but we'll get some very sort of highly erratic results if we just leave this as is as will be playing playing force infinitely but people work very well so let's grab ourselves the event tick because we will need to do some real-time calculations we're going to need our driver a little driver mesh let's drag off that yet physics angular velocity in degrees that's the one that we want and we want to negate this vector return it to zero let's be able to fight this by float we'll divide this by 0.5 when you get the victor down to half of what was and then from this event tick we want to add talk I'd talk in degrees to our driver okay now talk here tick the acceleration change just like our other torque nodes and this is our compensation this is going to compensate for the angle of the of the of the plane in return our values back to zero when there's no button pushed basically and from here oh well we're not a grab our driver I want to make sure if we come down here that enable gravity we want to uncheck this box because we're not even making our own gravity our own downward force so that our plane sort of drops out at the sky in a way that makes sense to us because we're not using the actual mass and the built-in gravity physics values in Unreal Engine we're going to do it sort of on our own so let's come out a little drive a note here we're going to add fourths look the sucks about chain check acceleration change and the force we're going to add is a negative force in these axis in other words Zed - which is downwards so minus 1500 would be a fairly good really good gravity value and with that done let's just hit compile make sure they're all set the next thing we do is want to use our throttle to calculate the speed of speed that our plane is moving so if we can do that then we can use our throttle to adjust how quickly it is that we're moving slow it down break that kind of thing and it's fairly similar to how we did it with with our controls here we're just going to make a new function for it though way to keep it encapsulated all this one where I calculate speed well now that we're in here let's grab our driver once more this is where all of our physics calculations are going to be applied is on this driver and we're going to come off here in two atps physics yet physics linear velocity now it's giving ourselves a little driving it anyway looks okay and we won't need to change our bone name just like a form will come out of the driver though it will get our forward vector going to be the direction forward that we're moving we want to get our throttle amount so we're dragging it get and when I multiply this throttle amount into a into a value that is that there makes sense for our physics objects in the world because 0 to 100 that's that's not a lot of force whatsoever but we multiply our throttle amount by 250 you start to get numbers that make a bit more sense and will come out here or I feel like look like we did before so we can find it clamp our float in a value in the emitter is going to be 0 which is going to be no motion to be stopped a maximum something very very high to 25,000 which is 100 times 250 should make sense so let's multiply this vector by our float was all of our clamp and then lap our current physical philosophy with the adjusted throttle amount so we'll come out of this vector here into a lap and when alert this vector bug in our two vectors here is a and B and our alpha value it's going to be 0.01 I make the adjustments pretty quickly and then out of our linear velocity node here we're going to set physics linear velocity well then we get set physics linear velocity driver new velocity is the world of our lab we do not want to add to current and we don't need to put in a bone name it's going to apply it straight to the object itself so we'll compile that head back to our event graph wrap our calculate speed and this is going to be attached to our event tick tree yeah all right so far so good it's at this point we can compile and save we'll head back to the editor was per player start somewhere up in the sky I hope yep there is supply starts up in the air let's go to world settings we got a game mode override doesn't matter it doesn't necessarily matter what that is we are default pawn class it's going to be our by playing pawn underscore VP so we'll just Sabel just to make sure and hit play not getting so getting out roll but we're not getting our motion I wonder whether it is silly me I can plug Tina her exes values oversight I guess it's cuz i was duplicating these trades i totally forgot to hook that up whatever the compiled save and there we go we have our plane motion and if we hold in shifts Oh a shift I don't think our shift is working we're not getting our print string coming out so let's ah no you know what it is I didn't hit looping on our set timer by function n so we'll hit compile on that hit play and now yeah as you can see as I'm holding in shift a throttle value is going up and the plane is getting quicker and then if I holding control plane is going to slow down to the point where it's just going to drop out of the sky a little plane get it by plane current moving on well one thing I noticed is that our spring arm could probably afford to be longer so let's set this to like a thousand and our lag could probably be bit greater let's just have a quick test here yes so we're seeing a bit more more of the spring arm lag all looking very good and we're ready to move on to the animation so we added a poseable mesh in our in our porn here instead of a skeletal mesh this would have to be using an animation blueprint we're just going to be affecting bones directly from here within the blueprint so let's make ourselves a new function this will be called prop rudder elevator mark the the three things that were there were going to be playing with and then we can start affecting things here in here in the function so we'll grab our poseable mesh because this is where all the bones are and let's come off here we need get bone rotation get brain rotation by name we'll plug this in your bone name that we want we double check over here in our skeleton but the propeller we want to propeller underscore J so I can copy that name and then paste it directly in here and we want to change this bone space drop down to component space so affecting in the component space not a world space rotation value and then out of the get bone rotation by name and you want to sit by and rotation by name set bone up transform come straight out of our puzzle Messier search bone rotation by name there it is we'll hook that up the bone name is going to be a propeller and a score J and R in rotation look if we just split these struck pins we can get to the XY and z values directly and come out of the the X our role our sideways value going to add 20 I think 20 is a good good figure is we're going to be using other set timer by function name in our event graph so every time this function ticks it's going to add 20 to the X rotation of our propeller to give the illusion that our propeller is spinning we'll also set this back to component space so that everything works out just fine and we could compile to make sure that works and then move on the next thing is the rudder so it's similarly to before I'll add just copy these two nodes because we're going to be using them and our set as well and what we want is the rudder who do the rudder next so copies like the phone name a paste rudder underscore J into each of these nodes remember to keep our target hooked up and I'll also connect it to our chain here Nevada is going to be affected by our access value I'll move right access Valley so if I right-click and go get move right I'm going to get the axis value that we are inputting from from here power left and right we're here we get crop rudder elevator so with this value will come out it will go to a multiplier a float multiplied by float but this is the number of degrees that the rudder is going to be rotating depending on whether we're moving left and right I think I picked a good value was minus 35 if we wanted to be we want the rudder to turn of the opposite direction of the plane rotates you know just so accurate like a like a real plane and I'll come out of our multiply here into a float in Terp float int f2 and we'll get the world Delta seconds act as a delta time currents current will be where it's at our target is going to be the result of this access value our current is the Z value of our of our current rudder rotation and then we plug in the result of our inter into the Z rotation of our set bone rotation by name node and that should all work just fine so let's go back we'll hit play oh yeah nothing's happening obviously because I haven't called the function so over here let's duplicate this set timer by function name like this in we want to set the time to something quite a bit lower 0.01 and function Ragosa compile and save there we go we've got some rudder going on the propeller is spinning very good so far so good the last thing we want to do is the elevators the elevators are a little bit trickier because they're not because they do a different thing like when we tilt the plane up and down they'll both go up and down but when we roll one is going to be up and one is going to be down so there's a little bit of extra calculation to keep to get on here but we can we can do it pretty simply so what does duplicate these measures again not much as these nodes because we're going to be using them for our elevator we'll just connect this up to our tree here and get let's do the left one first might as well go down a list so we'll paste that in and what we want to do is get our Brawl get our role access value and we want our move forward access value so this step up and down tilt our pitch and the role is our well it's our role and there's going to be a different a different result for each elevator based on based on the the access values that are coming into this function for I forget to make sure that your bone names are set properly in all of your nodes and let's come out of this roll into a multiplier float multiplied by float multiply our roll value by minus 30 and our move forward value by positive 30 this just like our butter it's the amount of degrees that they're going to rotate based on the inputs that we present them let's add these two values together combined both of these ISO values into the one the one node calculation here and we also want to clamp clamp our float because we don't want like a value of plus 30 and evaluate plus 32 equals 60 degrees of rotation for our elevator it's not going to look good when it's in motion so with this clamps will tape it at minus 30 and positive 30 and then get the world Delta seconds again I'll just grab we have this little note over here is we're going to use another F in tap F inter to our current will be the Y value as opposed to the the Z value that we use for elevator that's the upright the vertical rotation we want a horizontal rotation just that the pitch of Al I'm a bone here there was all about clamp is going to be the target the time is going to be the world Delta seconds and in terms speed will set at something higher like 10 it's going to happen fairly quickly the result of this interpolation goes into the Y the Y rotation of our elevator that's all that's all good in fact this compile and we'll play just so that we can yeah there we go so our our left elevator is working just fine all ready to do now is just duplicate all of these nodes hook this guy up and change the elevator underscore l eleska elevator understood elevator underscore the right-hand one and because it's going to be operating in the opposite sort of way we have to invert our roll value the move forward belly is going to say the same because like I mention before in the middle of pitches the elevator is going to be behaving in the same way but for the role the values have to be opposite for the left in the right left on the right fin so we'll compile that and save it and we'll just recap here it's really simple the simple node work here we're just getting bone rotation and then setting our blowing rotation by some some trivial calculation I know it looks like a lot of nodes but it isn't a lot of actual calculation so we'll hit save then back in the event just double-check that everything's going quite well and hit play there's our brother left and right elevators up and down and yeah they're changing and being affected depending on on which access keys represent them so set the speed up by high this is what a fun to play with I love making fun stuff I just brought this up on disco a week or so ago and yeah it's just it's just one of these really fun things that but I like to I like to make and I like to play with in fact just this this biplane I made for the toon shader video let's go to our world outliner grab the post-process volume find materials to make the both asset references and then down here in our outliner on the right letter and my content browser we want the turning shader sketch out liner and cell shading and then come back here to our porn by poseable mesh and then in details search for custom depth and tick this render custom depth pass now if we hit play so shaded plane look at that we shada by plane so anyway that's a that's really about all there is to it it's not that difficult and gives you a good little exercise on how physics works in Unreal Engine and we can play with a play with a very cool little plane and as a bonus for mannequin as our pilot so thanks you guys for watching this far this was lots of fun to make as I said and hope you keep making more fun stuff soon until then I'll catch you guys in the next video
Info
Channel: underscore
Views: 34,106
Rating: undefined out of 5
Keywords: ue4, unreal engine, tutorial, physics, player, pawn
Id: MM4YItRgKA8
Channel Id: undefined
Length: 27min 26sec (1646 seconds)
Published: Sun Feb 17 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.