Drive Your Boat - Boat Vehicle Tutorial for Unreal Engine 5.3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone this is a continuation of my last video and I guess you could say the boat Series where we created a buoyant boat and then masked out the water so make sure to check those videos out first if you haven't now what we're doing here is adding drivable functionality to this boat first we need to consider what controls the player will be using in this case that's move forward and backward turn left and right and E to enter and exit the boat so go to wherever you have your inputs in my case that's the default firsters input folder and then actions and that'll be I a move boat control D to duplicate I a steer boat and I a interact for a basic interaction so before I back out click on uh move boat and steer booat enter will open them both um and then change the value type to AIS 1D and then we're good to go so I'm going to back out of here because this is where epic has the input mapping context and let's go ahead and create a new one we'll call it IMC boat and as you you would guess we have to add move boat and steer boat but interact has to go into your default player uh context so I'm going to add that quickly here I interact and then you can click on this button here and press the key which in this case is e and it'll assign it okay now let's move on to IMC boat of course as I said I a move Boo and then I a steer booat each of these will have two mappings move boo will be assigned W and S and turnbo will be assigned d and a now W which is the positive x axis is the default forward vector and D which is the positive y AIS is the default right Vector that means S and A are the negative values so we need to add a negate modifier to S and a and that's it now that your input is configured open up your boat blueprint and let's add a a uh box Collision component I'll rename that to interact uh overlap and you just kind of want to set that up to whatever size uh you want so this is the point where the player is overlapping where they press e and they will get in the boat essentially and then uh of course go down make sure the player will actually overlap so by default that will be ignore everything except to overlap Pawn next we can go up uh to the actual mesh the boat mesh open that and we can add a socket for uh just player or player eyes or whatever you want to call it this is the attach point of the player so you can start off around the middle seat about so high and of course you can come back to this see how it looks and you can play around with the location of it but for now that's good so we're all done with the modifications to the boat now we can go to the actual player character again mine is in the default location now first of all we need a variable for controlled boat and set that to of course as you just saw the boat object okay now right click on the event graph and search for your interact event all right first of all you can drag out your boat variable get boat convert to validated get so this is whether we are in the boat or not so if not valid drag out a branch and this will be get overlapping actors so if we're overlapping a boat right and the condition will be is valid index so that's we're getting uh all the actors were overlapping and and we're the the filter is a boat so this will only return boats uh that the player is overlapping and then is valid index is basically is there even one so if there is we can get that one which is element uh index zero that's the first one or first we have to cast to boat right click convert to Pure cast now we can set boat and then we're going to attach attach actor to actor of course boat here is the parent the player the self is the Target and the socket is the socket we added in the mesh which remember the name was player for me location we want to snap to Target rotation keep world scale keep world don't mod so which means don't modify rotation don't modify scale we're only snapping location and then uh set actor enable Collision so this is just so you're not uh getting weird physics effects from overlapping with the boat and then disable movement of the player and finally get local viewing player controller get enhanced input local player subsystem and this is where we add our mapping context for the boat controls and it'll override the default walking controls as long as you set priority to one make sure you set this to to IMC boat okay and then before we test that let's quickly add I a move boat and I a steer boat just so I can print string and set that to0 seconds so it will not hang around so you'll only see the text when you're holding the button and plug in the value so you'll notice when I'm walking around you won't get any uh feedback here even though it's the same Keys remember so I'm walking around I'm pressing all the uh the boat control keys WD but I'm not getting anything now let's overlap the boat press e and now you see I'm pressing WD and we're getting feedback before we deal with movement let's deal with getting out of the boat so going back to the beginning if boat is set or if boat is not set so if we're not in a boat we get in the boat well we check for an overlapping boat then we get in the boat if we do have a boat we detach from actor and then all of these are keep world then we can set boat to nothing set movement mode back to walking set actor enable Collision or whatever you decided to do just put it back to the way it was and go over copy this to make it quicker remove mapping context and again make sure to set this to boat okay let's go try that we're in we're out but you see how you kind of I I clip through a little bit it's like launching me a bit so what I had set up here before was uh let's get root component to keep it as modular as possible you could do capsule component but again root component again it's just more modular um add relative location and this is just kind of just applies to this boat mesh and where the socket is which is why I included it a bit later all right see how now it's not causing issues with the boat mesh and like sending it flying all right so let's go on to movement so down to I I move boat this is actually a lot easier now so ont triggered add uh wait a minute add boat first get the boat variable or drag it out here either way add Force to that which will be the root component which is static mesh and then from the action value we need to turn this into a vector and right now this is World location so to convert that to you know relative to the boat I mean some people do different things I I always just get said actor whatever you're dealing with and I do get um actor rotation and then I rotate the input by the actor's rotation and make sure to click Excel change here um that way it doesn't use Mass it doesn't consider Mass on this Force which again just makes it more modular for other meshes um okay so there's an issue here kind of a special case so let me just show you this boat this is set up to send the boat forward right and X which is red is the forward Vector this mesh is actually rotated 90 degrees on the Zed value so positive Y is actually forward in this mesh ideally you would export the mesh and reimport it with a rotation but that's kind of annoying so I'm going to combine the Rotator here since we know the rotation that needs to happen 90° on the Zed value and that should do it one final thing I'll get in here and I'm holding W and it seems like nothing's happening because the value is so low inputs will only output a value between 0o and one so you can either multiply this by 100 or go into your input action itself which is what I'm going to do so IIA move boat and steer booat I'm going to open add a modifier scaler uh only the x value is relevant uh so I'll do 100 actually on move booat on move booat I'll do 250 but now we don't have to mess around with this and it keeps the code cleaner so let's try that out now we can go forward and backward and press e and we're out and we can walk around like normal final thing to do is set up the steering so once again we just get boat grab the static mesh component and all we got to do is add torque and uh on what axis right this is going to be the Zed axis so we split that and plug the input value directly into Zed again click this box and that really should do it let's go check it out okay well that's pretty much it let me know what you think let me know what else you want to see thanks for watching and I'll see you in the next one
Info
Channel: Peanut Games
Views: 2,542
Rating: undefined out of 5
Keywords: ue, ue4, ue5, unreal engine 4, unreal engine 5, game development, driveable, rideable, ridable, drivable, ue4 boat, ue5 boat, water, ue5 water, ship, boat
Id: cWyPVGsG3Dk
Channel Id: undefined
Length: 18min 27sec (1107 seconds)
Published: Sun Mar 31 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.