Motorbike (Motorcycle) Physics with Chaos Vehicles - Unreal Engine 5 Blueprints Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] [Music] this time we are covering a topic for which I got a lot of requests which is how to make a physics motorbike simulation using cow's vehicles and this is largely undocumented so you have to go through the source code and play a bit with some of the settings in the vehicle movement component but here it is that's what we'll be creating in this tutorial by the way if you want to get the ready-made project the link is in the description so you save yourself the time to do it and you also get some extra features for a small without further Ado let's get started okay the first thing that we need is to find ourselves a very nice motorbike model if you are a modeler of course you can create one yourself not as much of a modeler so I looked up something available for free on CG Trader and I found this one by the pyramid whom I would like to thank very much for sharing this with the community for free and you can download it by pressing on the free download button and then as soon as the link is available you can download direct to the blender file once we get this in blender we'll have to open it and do a bit of clean up because this model is staged for a screenshot the static rendering and actually we need to animate the leather also it needs a bit of rearrangement of the parts as well so let's download it by the way I already have it so I will not do it and once it's done you want to unzip it onto a folder and then open the blender file okay once we have the model in blender there are a few steps that we have to make in order to get it ready for a real I'm not going to show them in full because that's very time consuming but I will show you the main ones and we will do the final ones together so first you want to separate the different parts that we need to animate later so the byte has to have a body and the body has all the no moving parts and then we have a rear wheel the rear wheel has basically the tire The Rim the pigeon for the chain in this case the gear and the brake disc the brake caliper that is here of course is solid over the body front wheel is a bit more complicated because we have a fork and that one will have to be animated for steering so the front wheel also has the tire the rim and the brake disc the brake caliper of course is solidal to the fork because it moves with it second important thing is the pivot Points for all these parts Okay so for the rear wheel as you'll see the pivot point is placed in the center of the geometry both on the y-axis and on the x-axis as well on the rear there it is so one test we have to make go to the lateral View Take the Wheel in the center select it press R and then rotate around it so you should see it rotating properly even though here I think the texture was a bit of a defect but the wheel rotates properly [Music] you have to do the same thing for the font one which as a reminder is parent of the fork so selected R yes that also rotates properly now make sure that the wall bike is align toward the positive x-axis so it should be driving in the direction of the positive x-axis that's very important last thing as you see the fork as an inclination we need to fix that because we need to animate it along its local axis and right now the local axis is pointing up so we don't want that so the way to fix it is to eyeball its rotation so we rotate it until it's basically perpendicular and I think that we have you can eyeball it a bit a rotation of around 32.2 degrees in this model so let's clear the X and that's that because we don't need it now remember this number 32.2 degrees now we go object apply rotation okay now you see that the local axis is aligned with the fork and now we apply the same angle but negative and this time we do not apply the rotations for the rest all the rotations and the transformations of the model have been applied now if you see the dimensions of the model so let's for example select the body um we want to go to the scale to the scene sorry unit and Metric and then in this one we're going to put it to 0 0.01 because I really use a centimeter now you see that the model is super super tiny so we'll take a scale and let's put a hundred I think we need more because it was you know tiny to start with so the moment along the x-axis is like half a meter we don't want that so let's um probably this kind of bike should be what two and a half meters two meters so let's get it a bit more a to select everything scale and let's come up to let's say two and a half meters sounds about right if you have tops you can check on the internet uh What uh normal like size is but that this looks reasonable now back on to the view here okay we might want to do a g and realign it up on the x-axis not really necessary I think you can also stay here and the middle and let's check that our Fork has still oriented properly okay one last thing to do we will not use directly the wheels as a physics bonds we want to add our own so let's go into um basically select the front fork and inside okay let's select the front wheel and then we will add the tiny tiny mesh it can also be a scale zero mesh in place of it so let's add for example a cube of course I didn't take that position because the 3D cursor was not there so let's redo that once it's selected shift s and we say cursor to select so now we have the center add mesh Cube so now we have this Cube which is gigantic we can scale it down to almost nothing actually it's easier if you do it with the keyboard zero zero one S zero zero one became very tiny but it's in place and we'll make sure later on this parameter to the body but let's call it front physics wheel and then we do the same for the real one so select shift s cursor to selected good add mesh [Music] now we have a super time Cube which is in there and this Cube we call it over here physics well so that's good now both of these needs to be parented to the body so shift drag on top of the body and shapes right on top of the body and I guess they are not oriented are they maybe they were already presented and I am parent to them that's likely anyway they are now printed both to the body so to summarize we have the body with everything connected to it and you see that it has different materials will be used later on um then we have the front fork with its own orientation local orientation along this axis around which it will have to rotate by the way let's check the front this is Center yes looks also centered that is good and then we have the front wheel the visual one percent to it next we have the rear wheel also parameter to the body and then we have for the front wheel with the same people and with the rear wheel with the same pivot the invisible almost invisible cubes which we'll be using for as bones for the from the physics wheel and the rear fuse wheel so this is good we have one last step which is to apply all scales we don't want to apply the rotation otherwise we lose now the rotation of the front of the front fork but you might want to apply it as well so object select or with a object apply scale scales are applied and we basically should have descends size bike so you see the body seems to be 2.5 let's see the body with the fork so probably that's a decent side and we can use that as our model so last but not least oh file by the way let's save this s the other UE version of [Music] in case we want to make changes later [Music] and now with everything selected we go file export fbx now we're going to export it with this name by the way I have a number of presets for a real but so we want to export the selected objects we want to export only the mesh we don't need anything else scale as it stays as it is for a real the forward access is the x-axis and the app axis is the z-axis okay play unit use space transforms then we can really say it's geometry important not to get the warning to use face so smoothing phase why modifiers we have already applied them all that's very important uh you will do it before this part that I shown and then there will be no Armature so and we don't need to break an animation and we can export so this is how you prepare your model to be imported into a reel very important we didn't Ricket so we didn't add any Armature we didn't add any bone and the reason is that we'll be using a feature which is built into area to have it automatically read the model for you and that's the reason why we arranged it in this hierarchy the hierarchy will be used by unreal to automatically generate the bones now let's move on to importing this into unreal okay at this point we are ready to work in a real engine so let's start the Epic aperture and from there we will go to a real engine 5.2.1 which is the latest version and launch it once it is loaded we go to games and then we start a new project based on the vehicle template I will call it motorbike [Music] blueprint is fine desktop maximum quality we don't need any starter content or retracing so create we don't need to look into any plugins and the first thing we are going to do once the project opens is have a look at the structure so we have a few folders in this project let's look a bit closer we have the sport car sports car and then within the blueprint we also have the blueprints for the sport car so this is basically the scaffold mesh with also the animation blueprint uh control rig we'll talk about this bit later physics asset of course the skeleton and then its materials and then under the vehicle template blueprint we have the blueprint the main Pawn so this is the car we have a engine curve and third curve which we can reuse and then we have two blueprints one for the front wheel and one for the rear wheels what we want to do is make full copy of this and in here we'll be importing our bike later so let's start by making a full copy of the sports car so under the print we make a new folder and we call it [Music] filter [Music] and then we go back to sports car we select all of them and then we drag them on the chopper folder and at that point we are giving the possibility to do a copy so we'll copy them there you see four items copied so if we go into the chopper now we have the items we just need to rename them so let's follow the same logic the first one will rename it as chopperform first one this is the torque Curve will be there curve and the same for the wheels so basically whatever its name sports car will replace it with chapter [Music] and we spread it correctly okay now we have uh the foundation to build our Chopper but it's not yet the bike right however we want already to make sure that our game mode later on will spawn the bike and not the sports car so of course we can create an own game mode but let's reuse the current one so if we go under blueprints we'll find the virus game mode so this level is using the vehicle add game mode so that's the one we want to change and as you see this one is spawning as before Pawn the sports car so we want to change this to our chopperform the rest can stay the same compile and Save perfect and now we play everything works as it should but actually if we press f8 to eject for a moment and we check into the level we should see that the spawn Pawn is actually our chopper bone okay so that's exactly what we wanted means that the game mode is using properly the pawn that we have now set of course the pawn is still the sports car but we'll get to that in a moment okay now we are ready to import our bike into a real view of an Explorer and we look into the folder where we open the original blend file we'll find our exported fbx and also the copy that we saved there one folder above there is a texture folder so we're gonna cut this one and then paste it with informa so that we can tell area where to find the material there's only one texture in there but uh that's exactly what we need so that's done now within a real in the content drawer let's go under vehicles and create ourselves a chopper folder [Music] we can import the bike to and once we're in it we click import and then we find ourselves in the folder where our FB access and we select it open now this is very very important to have a real do automatically the rigging we need to force this to be imported as a skeletal mesh and set trending of the components we have created in the fbx volume render would be used for the rigging so let's Force this to be skeletal mesh and then we can also say to search materials locally if any and click import all sweet moment for a real to do its work there might be some messages like this that's fine that's that's even though uh okay a couple of partly then have a UE sets or you automatically create it for us that's fine and here you can see all the materials that have been created in blender of course these are not Unreal Engine materials so we might have to tweak a few of them but here is our bike and we have the skeletal mesh we have the physics asset which has been automatically created but we will have to fix it and now we have the skeleton as you can see we have no animation blueprint yet we'll do that at the later step first let's open the skeletal mesh and check few things so first of all you want to make sure that the orientation of the vehicle is correct so you see the bike is riding along the positive x-axis that's perfect so this will work the other thing you need to check is the approximate size so we have what parent is a very very long bike it's 4 meters and 28 so probably we could have sizes it bit smaller in in blender but that's fine you can always go back and resize it a bit uh this bike is huge it's like a car anyway it will work for the tutorial and the other thing that you want to do is move to the skeleton click on the bottom and make sure that the scale of the root bone the body is one one anything else will not work common mistake when exporting from blender is to have the wrong scale so if you see a scale of 100 that will not work so you have to go back to blender fix your scene units and make sure that it's exported with the proper dimensions since we are here let's also have a look at the bones so you see that we have the front fork bone and by the way if you see the orientation of the bone and the way it rotates that's exactly what we need and that's the reason why we gave it that Locker rotation in blender and the front wheel you can also check that this is not rotating as it should but let's get to the left mu and then selected front wheel now you see you seem to have a problem with it we have a problem which is given by the adjustments that we made to the fork okay so let's check if the rear wheel is rotating properly yes that one it is but the front is not so how do we fix that close we go back in blender let's reopen the modified blender file let's select the front wheel and if we look at the local axis you see that indeed it doesn't have the orientation it should have so the way to fix that is basically to only for the front wheel object apply rotation and now we have the correct rotation okay so once again we can select it all and by the way we can also get the chance to scale it a bit which we can do so let's select all yes I think that we should scale it by probably 0.75 [Music] better Dimension now remember object apply scale very very important let's save this as a new blender file file export fbx again select object mesh forward set up face I'm not sure we don't need and the bake we don't need and we can export it on top of the previous one so now let's close this actually make sure that we have saved the blender file and then back into a real content drawer in on the chopper skeletal mesh right click to import okay let's open it okay now the size is a bit better 3 meter 62 still quite a big bike but okay and let's now check that the front fork still has the right in condition and the phone will now rotate as expected okay so we have fixed the previous issue when you now see how that can be done note also that we have the front physics wheel added also updates on the right Axis and then we have the rear physics will which also rotates properly and of course these are not visible because they are the timeline cubes that we created but that's what exactly we need in order to have the physics be applied to these invisible wheels and then replicate the movement through the animation blueprint to the visible Wells okay now that we have checked everything is as it's shooting the skeletal mesh we can move on to the physics asset and as you can see this looks a bit like a mass so what we want to do is right click on body and then the little bodies below so we'll start from scratch okay now you don't see anything anymore on this little gear icon show all bones first thing is for the body we want to right click and add the shape at the Box okay we'll keep it very very simple box has been added but it's tiny so let's make it bigger and what we want to do is have a box which basically is covering pretty much the body and okay it's too large it's inside view and this will be good maybe a bit less that's fine buy a box uh because it's one is symmetric so that doesn't create any problem and the second one it's definitely easier to to work with right so um we can tweak it much more easily so let's you know use this level so it should not touch the floor because otherwise the bike will be sitting on this body and I've seen this error multiple times so make sure that there is a clearance below it okay now what we want to do is select the bone for the rear wheel right click and shape actually we can also do it from automatically here from the tools right so we'll say add body sphere and and all this so we get shape which is perfectly sized to the wheel now we go to Advanced and we scroll down until we see a body setup Primitives sphere and note the radius of the sphere that's 47 so we Ctrl C copy it and now we go to the rear physics wheel and we do the same so we'll add the body and then check that this body have the exact same radius which doesn't have so we go into the radius and we paste the previous one and now we can delete the body that was on the visual well okay so now the physics body is actually printed to the physics bone that we want to use so we'll do the same from the front wheel use the tool here to add the body we'll get it automatically the radius it needs let's check it 47 so copy that and then front wheel add the sphere as well go down with radius and paste it and of course we don't need this anymore so this concludes with the work that we have to do on the physics asset just make sure that there are constraints and actually according to the documentation we should also Force this to be kinematic so physics type kinematic and note that there is a bucket because this should change into a little lock but it doesn't let's see if after we save it ethics type kinematic so basically the two bodies two spheres that are part of the wheels we set them to kinematic also make sure that the constraints are positioned in the right place that's where the suspensions will go and I think we are ready to roll with this one so save actually let's also save here and let's save up the skeletal mesh with all the materials and let's close that now we're ready to go back to our blueprint Chopper folder and open the vehicle blueprint the chopper on and then inside mesh we can actually replace the skeletal mesh of the car with the scalar mesh of the chopper and if we go into the viewport now we have our Chopper now a couple of things to check for example the front camera yeah that that's nice I think I will put it in the position suppose the position of the head of the player and then the back camera yeah it's far in the distance that will work by the way we should already be able to check this as it will be spawned and yes it is spawn but of course it doesn't drive [Music] and it falls as well and it doesn't drive because we have not set up anything regarding the vehicle moving component and the physic now one thing that we have to do is back to the physics asset check the mass of the body okay for a motorbike we want to use a mass of 350 kilos so I check the mass property here and put in 350. save and backend blueprint under vehicle movement component if you search for Mass we will also give the same indication okay 350 kills compiles and remove the filter otherwise you don't see that the properties and say okay next we need to work on the configuration of the bike because of course you want it to be able to drive around so the first thing that we want to do is bike only has two wheels so here we need to delete will three and wheel two okay we only have two wheels first the front wheel so this one will be chop pair we have to select the correct blueprint for the wheels so remember that we have copied that from the sports car a nice Chopper will front and if you remember the bone is called front physics wheel make sure there are no spelling mistakes because otherwise it will not work and for the second we'll we'll use a Chopper wheel and of course not Wheels but it's wheel okay we keep it plural and here it will be rear T6 wheel okay so make sure that you use the right bone names if you are unsure you just go back to the physics asset here I'll make sure oh now the icons by the way are proper over skeletal skeleton and then you say okay from physics wheel you can also right click and do copy selectable names and then paste it in the vehicle movement component but otherwise I think you can remember them good so back into the vehicle movement component there are couple more adjustments that we have to make so since this is dedicated to a car so here we can leave everything as is but the steering setup needs to be changed okay so a motorbike doesn't have any Ackerman steering so we'll say single angle and you can use the angle ratio as these and keep it zero seven this one will adjust a bit later but for the bike we need a slightly different steering curve so what this does is changing the amount of steering proportional proportionally to the speed the faster you go and the less it will steer because otherwise it becomes difficult to control very high speed and there is one last thing that we want to do which is enable Center of mass override so a bike has a quite low Center of mass because of stability so in here we can input something like -40 so will be 40 centimeters below the center of that elongate the cube we have used as body physics body for the body of the bike okay so let's see how this works it might be different how this works maybe different for your bike you might have to tweak it a bit but that should give a bit more of extra stability so compile and Save and now let's see what happens to if we play okay starting to look like something of course it doesn't drive yet or does it yeah of course it does and as you can see it doesn't seem to be very stable actually it has a bit of stability already but we'll you know make this better what it doesn't do of course it doesn't animate yet but this is something that we can fix shortly okay one thing is to check one thing to check is okay where are my wheels you know is that sitting properly is it driving as it should and we can do that by using some debug features so one way to do it is here we can say if we type the back row we can see that under physics there is p physics chaos the bucket row enabled and we'll add a one so we enable that and then we do p k l dot chaos dots solver dot debug Drew shapes one and this one will show the fixed body which are used by the physics engine so if we play again now we see [Music] how our back is going and it doesn't matter if the physics body are lagging behind that's that's normal in the debug but you can see that we are already driving around with some issues here and there so let's have a look at the wheel blueprint and see if we have to make any adjustment so as we just know that our bike is skinning a lot so let's go into the blueprints for it and especially the rear wheel let's open that and under properties so first of all we'll reduce its 4D we have seen that from the sphere is more like 47 so we can for example you know put in a 45 just to make it a bit more similar to what it is in reality and that will help with the rotation speed the other one is friction multiplier uh it's a four let's put for example at a let's double it and see we get a bit more grip but we still have to add the torque control and the torque rotation control so let's prepare for that let's save and close actually make sure that affected by break it's fine uh by end break yeah and also by the engine so that's all good and now let's do the same with the front one I think that also has traveled with radio 45 where it is 45. we've always only affected by the break that's final and you know handbrake that's all good and compile and save as uh do another test drive we didn't adjust in this case the multiplier maybe seem to be steering well but let's see maybe we want to take this to four okay let's see if it writes a bit better by the way we still have our the back on still some great issues seems to be turning very quickly well let's see what happens once we have added the torque control so to add door control content drawer and let's go to the blueprint of the bike and under vehicle movement component if you scroll down at a certain point you will find section which is called arcade control okay so now bear with me because we have to put in a lot of numbers well not a lot but few so first of all we enable tour control and for rotation damping which is by default 0.02 we enter a 15 that will be a lot of rotational dumping useful for stability then in the Target rotation control section we enable that one and we also enable Roll versus speed enabled so what this does will adjust the roll depending on the speed and of course the inclination left or right inclination of the bike is related to roles will mostly be working on that so Road control scaling you want to enter a one roll Max angle 35 degrees and scroll down a rotation stiffness will enter 100. rotation dumping will enter 10 which is you know one tenth of what we enter for the rotation stiffness so it's a bit of rule of thumb Max acceleration will enter a hundred and then out of Center roll strength we'll put it to one and that's basically what we need to make this arcade control work properly for the bike of course if we are using it for different vehicle maybe an airplane or a boat you will have to use different numbers but for this bike with this mass and this setup that should be it so let's compile and Save and see how it drives and actually we want to turn off the debugging for the moment so if you use Arrow up you will see your previous debugging comma and I'm turning off calcified through enabled so we don't see any more debugging wait let's see if it drives a bit better and here we have torque control and yes that looks good I think that's uh let's get in closer too what we need for a bike and of course let's see at high speed maybe we'll still be skidding probably uh yes a bit oh okay yeah but that's normal of course I mean we can increase the lateral grip if we want to but that might not be necessary depending on the type of game that you are creating and actually drives pretty well even though I'm using my keys and not any joystick or any gamepad is driving fairly well let's see how it behaves on a jump we managed to get there wow looks good to me looks good to me okay last though we need to fix the animation oh by the way note that the front tire it's a big above the ground so actually we need this lightly smaller wheel radius apparently so let's fix that so back to content drawer front wheel at least the 45 maybe we need a 42. let's see what that's the case yeah better much much better looks good it looks good nice okay so last but not least we need to fix the animations of course because right now we are not animating the fork is not animating so we want to fix that okay so let's go to the um Vehicles folder and then under sports car we identify the animation blueprint of the sports car and we're gonna borrow this one so we don't have to reduce it from scratch but we could also easier to do it from scratch so I'm gonna take it and drag it on top of the chopper folder and then say copy here okay now this is still parented to the car so we want to do is right click signed skeleton and we'll use the select the choker skeleton and accept so once this is done you will see that also the thumbnail changes into the one offer our bike meaning that okay we are now parented to the bike and let's open the anim graph so first of all we have a control region here that we don't need so we're gonna delete the control rig okay and this component to local I think you can stay here now what we have is the wheel controller this comes from the vehicle movement component that is the one that is making the the wheel turn and also steer but we don't see them because this is applied actually to the physics well so what we want to do is uh well few things so first of all let's fix the steering part okay and for that we'll be using a look at the node so right click look [Music] at perfect and let's connect it connect it also to component to local and now let's configure this node so we want to modify this is basically the node for our Fork the front fork because we want to orient it depending on the steering angle that it applied to the invisible front physics wheel okay so we will use a look at axis of 0 0 1 0 that's perfect and we want to uncheck in local space but we want to use a lookup axis and this lookup axis is going to be 0 0 1 so basically it's a z oriented access and make sure that it's in local space and then down here we say okay what's your look at Target and our look at Target is the front physics wheel that's the one that we want to is a target for and for look at it's going to be 0 100 because we want to look laterally so along the lateral axis which is the axis of rotation and that's pretty much it so let's compile and Save and see whether we already get our steering and we don't see it so let's go back to the animation blueprint and actually the problem is we didn't assign it so blueprints topper open the blueprint go to the mesh and you see that we are still using the animation blueprint of the car but now this is assigned to different schedules and would never work and now let's find the animation blueprint actually for the chopper we have two because we haven't renamed it so that's not very handy so let's go in here and rename this one yes jumper and MVP so now we can tell it apart from the other so back into the blueprint skeletal mesh and let's now select our Chopper animation blueprint and here it is compile and save and now let's see if whether the steering works and yes it does uh perfect so now we have the steering actually working also nicely I would say and remember we didn't adjust yet the steering for for Speed so we have still to adjust a bit the steering curve but that looks already good so next we want to make the wheels rotate because of the moment there are not so back into the um content drawer and into our vehicles Chopper folder let's open again the animation blueprint and let's give ourselves a bit of room so basically what we are doing for the rear wheel that's easy we are going to use a copy boner node by the way everything I'm doing here can also be done with the control rig but you know this is nicely easier at least for a tutorial of this guy and then we're gonna do a copy rotation and the rotation that we want to copy is from well search bone that will be the real physics wheel and Target bone that will be the rear wheel so very easy to compile and save and let's test it already this is always nice to see our modifications are working and yes now you'll see the rear wheel properly rotating so that's pretty cool and now let's do the same for the uh front wheel so again open the animation blueprint give me give ourselves with rule actually we can control D duplicate this node and just stick it in and let's do real physics will actually now we have to change it to front with XL and it will rotate the front wheel now let's see how that works [Music] and apparently works well so we have actually I would have the tendency to now I think it's fine I wanted to adjust them slightly more the radius for the front wheel looks good from here you might have a different taste okay depends on how you like it also when a bike is inclining you might want a different uh you can feel but that's up to you of course yeah right now it looks like the is going a bit into the terrain anyways I think that's uh conclusion of our tutorial and that's exactly what we have built easily using the arcade controls of cows Vehicles which of course are undocumented but uh by looking into the source code and with a bit of Trials and errors I think you can really work with them and our bike is also nicely doing evolutions through this uh posts so I think that's it let's conclude with a nice jump Maybe and thanks for watching and see you in the next tutorial
Info
Channel: Marco Ghislanzoni
Views: 16,820
Rating: undefined out of 5
Keywords:
Id: ofwC1LGAJ3s
Channel Id: undefined
Length: 51min 12sec (3072 seconds)
Published: Sun Jun 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.