IntroductionIn this tutorial we will be using Blender to take a vehicle model and rig it for use in UT3 and then going through the process of adding all the necessary parts in Unreal Editor and finally the required code. This tutorial assumes some familiarity with blender and that you have a model ready and UV mapped (see the CustomGunTutorial for details on UV and Normal Mapping) Getting StartedOK so we are going to make a new wheeled vehicle based on the hellbender. I'm going to assume you have already followed the custom weapon tutorial so will not explain in any depth bits I've already covered there. OK to get started we need to work out units and orientations. If you already have a model you want to use you will need to orient the mesh accordingly and ensure the sizes are about right. So your vehicles length extends into the X axis it's width into the Y and height into the Z. The front is towards the positive X axis so from the Front view (pressing 1 on the numpad, which in this case shows you the side of the vehicle due to its orientation) the front of the vehicle heads towards the right of the screen and Up is Up the screen. Data should be more or less centred about the origin. Dimensions wise I've used X of 200 Y of 100 and Z of 50 for my starting shape. For the hellbender shape we need a few things on our model. We need four tires (any more or any less and we'd need to more extensively modify the code), a MainTurret with a seat for the gunner and a smaller secondary turret for the driver to fire. We can also add some suspension to the model that the physics animation will play with. We could add more stuff like damage modelling and parts to fall off when it gets hit and more elaborate animations but for now we will stick with the basics. A Bit More on UV'sA quick note on the UV's for this model We looked at how to do UV mapping in the custom gun tutorial. Here I've followed more or less the same proceedure then done some more hand tweaking to make things look better. Here is my model after initial unwrap and the UV generated I've added a UV test grid to show how the texture is mapping to the model. This is a handy trick to see how the image distorts as it's applied to the mesh. You can see the wheels are distorted quite a bit and a number of places look like they could use some work. In addition the mesh is not making the best use of the texture space available. I projected the Wheels from the view and fiddled about some more to get this You can see straight away the wheels now are much clearer and various improvements to the way the texturing is applied. The map also better uses the space available though it less of the texture just being unused space and wasted resolution. The texture is a little closely spaced in some parts just for ease of painting it's nice to separate areas a little or there is the chance of over painting edges. The final tweak just moves things around a bit and fixes the turret You can put a lot more time into this than that but for this basic tutorial a few little tweaks are probably enough. Rigging The ModelNow for this model to work we need bones underneath to move the various parts. Bone orientation is a little odd but once you have the first bone correctly orientated you can just duplicate it. Shows the correct bone orientation. Create an armature at the origin and move the tip of the bone so it faces the correct direction. The base of the bone is the pivot point. Name this first bone Base. Now we add the relevant bones, names are important as they will be used to tie our model into the script and animation tree in Unreal later. Create a bone at each of your wheels locate them at the pivot point of the wheel where it will roll and turn through. Name these bones Lt_Front_Tire Rt_Front_Tire Lt_Rear_Tire and Rt_Rear_Tire. Parent them all to the Base bone. Make a copy of all of the bones and reposition them at the wheel end of the suspention (in the hellbender model this is the same location as the tires). Rename these four bones to Lt_Front_Suspension,Rt_Front_Suspension,Lt_Rear_Suspension and Rt_Rear_Suspension. Copy these four bones again and then move them to the top of the shocks on your model. Rename them Lt_Front_ShockAim,Rt_Front_ShockAim,Lt_Rear_ShockAim and Rt_Rear_ShockAim. When you are done you should have something that looks like this: Now we need to rig the turrets. Copy the base bone and rename it BaseOffset. Move it up a bit on the Z axis and parent it to Base. Now duplicate it again and move it to base of your main turret the point it will swivel around. Rename it MainTurretYaw and parent it to base offset. Duplicate the bone again and then position it so it will be at the pivot point of the turret. Call this bone MainTurretPitch and parent it to MainTurretYaw. Bones are heirachical so the rotation and movement of a parent bone affects all the children this allows us to make complex behaviours with a few bones. Now we will rig the secondary turret. Duplicate a bone and place it at the turrets base pivot point and name this SecondaryTurretYaw set it's parent to BaseOffset. Duplicate it and move the duplicate to the updown pivot name it SecondaryTurretPitch and set it's parent to SecondaryTurretYaw. Duplicate another bone place it at the end of the turret call it SecondaryTurretBarrel and set it's parent to SecondaryTurretPitch. So now you should have something like The tree stucture should be
Now we have our bones in place we need to add the vertex groups to control the mesh. Select the Mesh then the Armature then press Ctrl+P select Make Parent to Armature then Select Create Name Groups as before. For people more familar with blender note that we are not using the Armature modifier. This is todo with the export script. Now go through and assign the mesh points to the bones. The main body to the base the wheels to their respective Tire Bones and the suspension to the suspension bones. The various bits of the turrets to the their respective bones (so base to Yaw main gun to pitch) Now we have our model rigged and ready to go. Exporting The Model to UT3First we need to check the normals are OK and then convert to triangles. So with the mesh selected hit Ctrl+N and click the dialogue that pops up to recalculate the normals outsid. Normals are used in backface culling (basically working out which sides of the model are inside so don't need rendering) if the normals are wrong your model will be insideout. Then press Ctrl+T to convert to triangles UT3 preferes triangles to quads that blender works in. With that done export your model using the Export script as in the gun tutorial. By going to the script window clicking scripts and then Export then the PSK/PSA exporter script Importing Into Unreal EdOk now we fire up Unreal Editor Once it's loaded open the generic browser and start a new package by clicking File New Name it something appropriate I'm using VH_CustomCar1 if you use something different just be sure to replace it in the later stages. Select the group Materials and Material from the drop down and name the asset VH_CustomCar1_Mat. Now import you various models and textures. I called my Model SK_CustomCar1 and put it in the Mesh Group. Set the material up and tell the mesh to use it by entering it into the materials option in the mesh tab. You should get something like this Adding SocketsOK while we are in here we may as well set up the sockets. Select the "Mesh" Menu then "Socket Manager" Now we need to add the relevant sockets. Again this is mostly just copying from the Hellbender. Hit New Socket the fill in the details.
You are going to want to reposition these a little till if fits with your model. Basically the two view sockets are where the camera is positioned for either Driver or Turret. The Fire Sockets are where the guns fire from. For the Main Turret you want to move that towards the end of the main gun. And the seat socket is where the player model is positioned when someone is sitting in the turret. You can reposition a socket simply by clicking on it in the list then clicking the red green and blue XYZ controls in the 3d window. You and translate or rotate by clicking different tool on the bar. At the end it should look like this. Adding Physics ModelNow we need to add the physics stuff. First right click and add a new PhysicalMaterial by selecting it from the list and clicking Call it PhysicalMaterial and Group Materials. In the box that pops up goto PhysicalMaterialProperty and click the little blue triangle then the popup that appears. The enter "Metal" into the box. Now copy that material (by doing right click on it duplicate) leave almost all the settings the same just rename it PhysicalMaterialDrive. Open it by double clicking and click the bEnableAnisotropicFriction and set the AnisoFrictionDirection X to 1 Now we need to setup the Physics Asset. Go into the Mesh group right click your skeletal Mesh (SK_CustomCar1) Click create new physics asset name it "SK_CustomCar1_Physics" and leave it in the Mesh group. click OK till a window comes up with a load of boxes round your mesh. This is the collision model. Most of it will be wrong since most of the bones do their own thing. Go through selecting all the boxes but base and deleting them from the tree. The resize and shift the the original one to cover the model adding more as appropriate. Look at the hellbender physics model if you want to see roughly how it should be done. You can move the boxes by clicking them in the tree and selecting the control on the top then left clicking one of the highlighted axes. Once you are happy add the physical material by click the boxes (anyone will do) then selecting PhysicalMaterial in the browser under Materials and then pressing the green arrow in PHAT window. Adding AnimTreeOK one more thing to do we need to build an anim tree to tie our script and models bones together. Right click on the general browser and select AnimTree The familar dialogue pops up. Enter group "Anims" and name "VH_CustomCar1_AnimTree" and hit OK. The AnimTree editor should pop up. Ok first we need to set up our bones Left click the little animtree box on the node diagram then in the set of options bellow find PreviewSkelMesh. Enter our skeletal mesh either manually or by selecting it in the browser and clicking the arrow. Now it knows what skeletal mesh to look at we can add our bones to it. Right click the AnimTree and click Add SkeletalControlChain then you will get a dropdown list of bones Leftclick Lt_Front_Tire That entry should appear on the animtree. add the following bones to the list. Rt_Front_Tire ,Lt_Rear_Tire ,Rt_Rear_Tire ,Lt_Front_Suspension ,Rt_Front_Suspension ,Lt_Rear_Suspension ,Rt_Rear_Suspension ,Lt_Front_ShockAim ,Rt_Front_ShockAim ,Lt_Rear_ShockAim ,Rt_Rear_ShockAim, MainTurretYaw, MainTurretPitch, SecondaryTurretYaw, and SecondaryTurretPitch. when you are done it will look something like this. The order is not overly important but grouping the various tire's suspension and shockaim together makes things neater. Now we need to add the controllers. First left click on the area and add a AnimSequencePlayer node. In the sequence name put AnimPlayer then connect it to Animation socket by dragging an arrow from its out point to the Animation connection on the tree. Much like we did with materials and textures. I think this sorts out the animations but I'm not completely sure :S OK now on to the bit I do understand :D Add a SkeletalControlWheel node by right clicking and selecting the option. This will map out scripts control actions to our wheel bones in the game and we will need one for each of them. First lets save ourselves some work by setting the first one up then we can duplicate it. With the node selected In the controls under wheel set the WheelRollAxis and WheelSteeringAxis The 3d view helps you get this right if you connect the control the axis show up. If your model is like mine then it should be RollAxis Axis_Y and SteeringAxis Axis_Z Set the name under the controller section to Lt_Front_Control. Now select it in the window if it isn't already and press ctrl+W this will duplicate it. Duplicate till you have 4 Wheel controls in total. Rename them Rt_Front_Control Lt_Rear_Control and Rt_Rear_Control and connect them to their respective tires Add a SkelControlLookAt Node to the tree. Set it's Target Location Space to BCS_OtherBoneSpace LookAt AXIS_X upaxis AXIS_Z TargetSpaceBoneName: Lt_Front_Tire and set bInvertLookAtAxis. This control basicaly points one bone at another and in this case it points our suspension pointing at the wheel. Duplicate till you have four total de do them for each of the tire bones binding them to their respective suspension. Now add another SkelControlLookAt set this one to Target Location Space to BCS_OtherBoneSpace LookAt AXIS_Z upaxis AXIS_Z TargetSpaceBoneName: Lt_Front_Suspension duplicate it till you have four total and set the TargetSpaceBoneName in each one to the correct setting then connect them up. OK now we come to our turrets. Add a UTSkelControl_TurretConstrained Node connect it to MainTurretYaw and then set the following. bConstrainPitch = true bConstrainRoll=true bResetWhenUnattended =true ControllerName = "TurretConstraintYaw". Add another UTSkelControl_TurretConstrained Node connect it to MainTurretPitch and then set the following. bConstrainPitch = true bConstrainRoll=true MaxAngle PitchConstriant = 90 MinAngle PitchConstriant =-40 bResetWhenUnattended =true ControllerName = "TurretConstraintPitch". add two more UTSkelControl_TurretConstrained Nodes set each as follows connect it to SecondaryTurretYaw and then set the following. bConstrainPitch = true bConstrainRoll=true ControllerName = "GunnerConstraintYaw". connect it to SecondaryTurretPitch and then set the following. bConstrainPitch = true bConstrainRoll=true MaxAngle (PitchConstriant = 90 YawConstraint = 120) MinAngle (PitchConstriant =-10 yawconstraint = -120) ControllerName = "GunnerConstraint". these numbers are all changable based on your model these are just the ones the hellbender uses. Be careful with naming here if you misspell or use different names Unreal has a habit of crashing when it can't find the bones specified. If it does crash look in the log fine in your UTGame\logs directory to get some clues as to what has gone wrong. These controls basically allow us to control a turret with our view but they constrain it's movements slightly to mimic the restrictions of the gun on the vehicle. With that done and connected we are ready to add some script to this thing. Adding Unreal ScriptFirst save the package. The close Unreal Ed. Copy the saved package from UnrealTournament3/UTGame/unpublished/cookedpc to UnrealTournament3/UTGame/published/cookedpc so the compiler can find it. One quick note if you are using Notepad++ it had a habit of making the files unicode which unreal's compiler can't read and it spits out an error like this "Error, Unexpected 'i'. Compile aborted due to error." just set the format to Ansi and it should then compile ... or fail with a more meaningful error :D. The three code files that run our modified hellbender can be found here. http://steam-punk-pirates-mod.googlecode.com/svn/trunk/TutorialCode/CustomCar/UTVehicleFactory_CustomCar1.uc Each file does a different bit. The UTVehicle_CustomCar1.uc defines out car and it's wheels for the system to simulate. UTVechicle_CustomCar1_Content.uc extends that and adds mesh seats physics etc. UTVehicleFactory_CustomCar1.uc is a object factory that can be place in a level and will make our car object. The factory is the simpest it just extends the normal factory object with support for our own vehicle. So let's look at it more detail. Line 3 is defining the new class as an extension of the standard UTVehicleFactory. We then define the default properties at line 5. First we are setting up an object using our vehicles static mesh. This will be the object we see in the game when we look at the factory. Lines 14-18 we are defining a collision cylinder so we can't walk through the object. lines 20 -21 we are giving the factory the path to the Vehicle itself so it can make it when someone jumps in the vehicle. Now the base UTVehicle_CustomCar1.uc A little more complex. Line 5 is defining this new Vehicle as an extension of the UTVehicle class. Most of the rest of this is now inherited code from the hellbender (some of which we probably don't use) setting up variables like the turrets the sounds and so on. DefaultProperties line 81 - 102 setting various features like health weight how sensitive the steering top speed. These are all parameters that can be altered to change the characteristics of the vehicle. Lines 104-107 sets up the simulation using the hellbender code. I assume this is physics modeling. Line 109-114 is defining one of the wheels. Note the bone name matches what we used in our model and the Skeletal control is the same as the one we used in the AnimTree. Lines 117 - 147 is basically repeating the setting up with all four wheels. the rest of the code is more parameters. and the final file UTVehicle_CustomCar1_Content.uc This code extend the code we did for UTVehicle_CustomCar1. That might mean we could consolidate this into one file since it seems a little redundant to extend the base class then extend again unless for some reason we need to get at the non extended version for some reason. A few more bits of hellbender code then on to the default properties at line 40 ish Line 43 we are defining our vehicle object. Line 44 is setting the skeletalMesh to use, Line 45 is setting the physics, and Line 46 is giving it the AnimTree. Line 47 seems to be setting some physics stuff. After that the next big thing is defining the seats at line 55-66 for seat 0 or the drivers seat and 68-84 for the turret. So lets look at this more closely. Line 55 we define the seat(0) and then tell unreal what is in it. We set the gun class to a type of shock turret and then tell it what the socket for the gun is on line 56. Line 57 details the turret controls notice these are linked to the skeletalcontrol we set up earlier. We also tell it the pivot point the bone it should rotate about at line 58. Line 59 tells us where to put the driver camera and there is some offset and stuff on the following two lines. Line 63 tells us how much damage the driver of this seat takes if the vehicle is hit in this case zero. The the final two lines define muzzle flare and weapon effects. The next seat definition is very similar using the bones and controls for the main turret instead. Notable difference are line 76 the person in the seat will take damage and the seat is visible line 80. Line 81 tells it where the seat bone is and so where to position the player model. After that there is some stuff about the sound effects and the particles. At line 165 -166 you see how the Physical materials are set we have two one for default state and one for out driving state. So with the code complete you just need to compile it with Unreal then give it a whirl. Putting the Vehicle In UnrealTo test out vehicles you will need a level. I just made a basic death match level with some floors and a couple of walls then dumped the vehicles in there for a drive around. To get your custom vehicles in a level open the generic browser got to the Actor Classes tab find NavigationalPoint in the tree. Then UTVehicleFactory go down that list till you find our new vehicle factory UTVehicleFactory_CustomCar1 and select it. Now go to your 3d view of the level. Right click where you want to put your vehicle and the select the Add UTVehicleFactory_CustomCar1 Here option. The mesh for your vehicle should appear. You can now play the level by right clicking anywhere and clicking play from here. You may need to rebuild the level before this step by hitting build all. Final In Game ShotsSo there you have it and to round things off a few pictures of the new vehicle in action. I thing the suspension needs some work I may have bound the wrong bits together. Something to look at in the future. | ||||||||||||
hey greetings thanks for your wonderfull tutorials! since i am a blender user i really apprecieted to see it in action with UDK =) i have tried to make an airplane model, but i have some issue when i export to psk and import it into udk. I think is something related to the UV mapping, when i import the model it's like texture is coming out the model... i have already recalculated normals but nothing changed. I have no applied texture or mat in blender to it, so it uses the default text into udk. I have also tried to export the model in .ASE format and import it into udk, i have no issues with that, it looks as it look in blender with no normals problem... can you adress a possible cause of this problem?
thx Marco "Piddu"
I have occasionally seen things like this where for some reason, maybe down to a slightly odd topology of the mesh confusing blender, the normals are the reverse of what you want for either all or part of a mesh.
Blender usually uses double sided meshes so it's not always obvious this has happened till you export (you can turn this off in the editing panel (F9) Mesh box and unclick the "Double Sided" button then back faces will show up as black in the standard object view). You could also turn on the "draw normals" in edit mode under Edit Panel F9 "mesh tools more". This will draw the normals in blue lines on each of the faces (the front or visible face is the one these point out of) you can also adjust the "NSize" slider to make them more/less visible.
Depending on how much of your model is inside out you can then either recalculate the normals inside with CTRL+SHIFT+N (which just calculates the inverse of the usual CTRL+N) or select the faces which have gone wrong and manually flip the normals till they are correct using CTRL+F then click "flip normals" (this does exactly what it says flipping the normals to the reverse of their current value so if they point in they will point out and vice versa)
Hey there,
This tutorial is probably the best i've found for UT3 vehicle editing so far - it's cleared a lot of stuff up, so thanks for that :)
I do have some issues though - and as always it's with scripting. I've followed the naming conventions to the letter, and have tried compiling with the three extra scripts in the relevant Classes folder, but I am getting compiling errors to do with the TakeRadiusDamage? function (apparently it's already been defined). I don't suppose you have any ideas on what this could be?
Oh, additionally, i'm using UDK instead of UT3 as it's quicker at compiling, but UDK doesn't have the Hellbender in it's content. Could this be the cause of the problem? I've been looking at this for days with no luck.
Hope the SPP Mod is going well!
-Rez
Hey there,
I've stripped down a lot of what you guys have done into a very simple 4-wheeled vehicle. Nothing fancy, no turrets, one seat. I'm using the 2010-07 build of UDK, with Maya 2011 and exporting through FBX.
I'm having two problems right now:
1) My vehicle's wheels do not spin when I press W or S 2) My vehicle factory spawns the vehicle at an odd rotation (90 degree roll, and maybe 45 degrees in Z), and I can't get it to land upright.
Have you guys run into these issues before, if so, what was the cause of the problem?
Thanks,
-Ozz
could you please add/upload or email Cartut7.jpg? It has a dead link and that picture is important to me.
I have no idea how to script and would love help on geting my 1 wheeled vehicle into my game I have built if anyone can do this for me I would really apreciate it. Please email me at bparrish77@gmail.com I will gladly give you my files and see if we can get this thing working. I have a deadline to get this in and this is the part I am stuck on.
Hi I have tried to do a simple 4-wheeled vehicle. I deleted the guns code, one seat and change Hellbender to scorpion cause i use UDK not UT3. I am having problems 1. the car doesnt detect the player when it get near the car. But if i use another car to hit it the collision work (but not shoot) what can I do??