Cleanup is going to take awhile, so the site is back up but editing has been disabled.

Vehicle Modeling

From HalfLife 2 Knowledge Base

Jump to: navigation, search

Creating a model for use as a prop_vehicle_jeep V2.0

by Cannonfodder


Here is a zip file which contains this tutorial plus the smd's, qc and ms3d file: [1]

To create a replacement model for the jeep we first create the model in a 3d program. For this tutorial I use Milkshape 3D. I am assuming you have some basic knowledge of Milkshape 3D for this tutorial. If not there are plenty of good tutorials. I am also assuming you know how to import static models into half-life since I do not describe how to do the texturing in this tutorial.

For a simple car, make a block for the body and four cylinders for the wheels. Assign materials to all the various pieces. Also assign each piece to a separate smoothing group. This looks like the following:

Image:Car1.gif

Now you need to add 11 joints. One for the body, one for each wheel, one for each wheel/axel, one for the drivers viewpoint reference, and one for the gun location. Name these car.body, car.wheel_fr, car.wheel_fl, car.wheel_rr, car.axel_rl, car.axel_fr, car.axel_fl, car.axel_rr, car.axel_rl, car.view and car.gun. Make sure the wheel joints are correct. If you mix up one of the joints you will get VERY weird results when you try and drive the car.

After adding the joints you model should look like this:

Image:Car2.gif

Save your model. Now export as smd using the following file->export->HALF-LIFE smd... Name the file car_ref.smd and select reference.

On to the animations... There are three sets of animations. One to rotate the wheels, one for steering the front wheels and one for bouncing the wheels when they hit the ground. You will need to create 14 animations. After creating each smd you need to clear the key frame you created. Otherwise the changes will add on to each other in weird ways. You can do this with the animation->delete key frame or animation->remove all key frames.

Wheel rotation animations Each wheel rotation animation is done using three separate single frame animations. You will create two smd files for each wheel. This plus the idle animation will describe the rotation of the wheels to Half-Life.

Go into animation mode by pressing the animation button and change the length of the animation to 1 frame. Create a key frame with control-K and export the animation. To do this use file->export->HALF-LIFE smd... , name it car_idle.smd and select sequence.

Now we create the second animation for the front right wheel. Select the right front wheel joint and rotate it 120 degrees in the Z dimension If this rotates your wheel backwards or sideways then your car is facing the wrong direction. Now create a keyframe with control-K and export another smd. This time name it car_spin_fr120.smd and select sequence. This is what it should look like after rotating the right front wheel:

Image:Car3.gif

Now we create the third animation for the right front wheel. Select the right front wheel joint again and rotate it another 120 degrees in the Z dimension Now create a key frame with control-K and export another smd. This time name it car_spin_fr240.smd and select sequence. Here is how it should look:

Image:Car4.gif

Each of these animations is done on the FIRST frame of the animation. Do not add any additional animation frames.

Now you need to create animations for the other wheels. Use animation->delete key frame to clear the previous key frame. Select the left front wheel joint and create car_spin_fl120.smd car_spin_fl240.smd. Clear the key frame again and select the right rear wheel joint and create car_spin_rr120.smd car_spin_rr240.smd Clear the key frame one more time and create car_spin_rl120.smd car_spin_rl240.smd. You have now created all the animations you need to describe the wheel rotations.

Steering animation

You need to create two animations for steering. First clear your key frames again. In animation mode select the left front axel and rotate it 45 degrees in Y dimension. Now select the right front axel and rotate it 45 degrees. Create a key frame with control-K. Write out an smd with the name car_steer0.smd and select sequence. Your model should look like the following:


Image:Car5.gif

Now rotate the left front axel back -90 degrees so that it is -45 degrees from the idle location. Do the same with the right front axel. Create a key frame with control-K. Write out an smd with the name car_steer1.smd and select sequence. Your model should look like the following:

Image:Car6.gif

Suspension animation If you want the wheels to bounce when you make jumps in your car you need to create the suspension animations. There is one for each wheel. Clear any previous key-frames and go into animation mode. Select the right front axel and move it +15 in the Y direction. Create a key-frame. Write out an smd with the name car_jump_fr0.smd and select sequence. Your model should look like the following:


Image:Car7.gif

Clear the key frame and select the left front axel and raise it +15 in the Y direction. Create a key-frame. Write out an smd with the name car_jump_fl0.smd and select sequence. Nor do the same with the rear axels and create car_jump_rl0.smd and car_jump_rr0.smd

You have now created all the smd's you need for your car. Whew !!!!


Now we create the phy model. You could use the same file as the ref model, but you will get sparks when you turn because the wheels will hit the ground. First get out of animation mode. Now save your model again just in case you forgot before. DELETE all the wheels. Export the smd and name the file car_phy.smd. Select reference. If you have a complicated vehicle you can create anything you want for the phy model using boxes. Just keep all the joints the same as in the ref model and assign all the boxes to the car.body joint. Assign each box you create to a different smoothing group, otherwise you will get a bad smoothing group error when you run studiomdl and your collision model will be wrong. Here is a picture of the phy model:

Image:Car8.gif

You are now ready to import the model into half-life. Create the following smd. This smd now creates all the animation blends correctly !!! The gun does not yet work though.


 $modelname "cartut\car.mdl" 
 $scale 1.0 
 $body "Body" e:\hl2\hl2\models\cartut\car_ref.smd 
 $cd "\hl2\hl2\models\cartut" 
 
 // These pose parameters tell half-life how far the wheel can spin. 
 $poseparameter vehicle_wheel_fr_spin -180 180 loop 360 
 $poseparameter vehicle_wheel_fl_spin -180 180 loop 360 
 $poseparameter vehicle_wheel_rl_spin -180 180 loop 360 
 $poseparameter vehicle_wheel_rr_spin -180 180 loop 360 
 }
 
 // This pose parameter tells controls the needle on the spedometer. 
 $poseparameter vehicle_guage 0 1 
 
 // This pose parameter tells half-life how to steer. 
 $poseparameter vehicle_steer -1 1 
 
 $poseparameter vehicle_weapon_yaw -120 120 
 $poseparameter vehicle_weapon_pitch -60 60 
 
 // These pose parameters tell half-life handle the wheel suspension. 
 $poseparameter vehicle_wheel_fl_height 0 1 
 $poseparameter vehicle_wheel_fr_height 0 1 
 $poseparameter vehicle_wheel_rl_height 0 1 
 $poseparameter vehicle_wheel_rr_height 0 1 
 
 // These specify the various animations which are referred to below 
 $animation idle_anim "car_idle" 
 
 $animation spin_anim000 "car_idle"   subtract idle_anim 0 
 
 // These are all the animations for the tire rotation 
 $animation spin_anim_fr120 "car_spin_fr120" subtract idle_anim 0 
 $animation spin_anim_fr240 "car_spin_fr240" subtract idle_anim 0 
 $animation spin_anim_fl120 "car_spin_fl120" subtract idle_anim 0 
 $animation spin_anim_fl240 "car_spin_fl240" subtract idle_anim 0 
 $animation spin_anim_rr120 "car_spin_rr120" subtract idle_anim 0 
 $animation spin_anim_rr240 "car_spin_rr240" subtract idle_anim 0 
 $animation spin_anim_rl120 "car_spin_rl120" subtract idle_anim 0 
 $animation spin_anim_rl240 "car_spin_rl240" subtract idle_anim 0 
 
 // These are the two animations for the steering 
 $animation steer_anim0 "car_steer0" subtract idle_anim 0 
 $animation steer_anim1 "car_steer1" subtract idle_anim 0 
 
 // These are the animations for the wheel suspension 
 $animation jump_anim_fr0 "car_jump_fr0" subtract idle_anim 0 
 $animation jump_anim_fl0 "car_jump_fl0" subtract idle_anim 0 
 $animation jump_anim_rr0 "car_jump_rr0" subtract idle_anim 0 
 $animation jump_anim_rl0 "car_jump_rl0" subtract idle_anim 0 
 
 // This is the main sequence upon which everything else is based 
 $sequence idle idle_anim fps 30 ACT_IDLE 2 
 
 // This is the blended sequence which describes how to rotate the front right wheel 
 $sequence wheel_fr_spin spin_anim000 fps 30  { 
   blend vehicle_wheel_fr_spin -180 180 
   blendwidth 4 
   delta 
   autoplay 
    spin_anim_fr240 spin_anim_fr120 spin_anim000 
 } 
 
 // This is the blended sequence which describes how to rotate the front left wheel 
 $sequence wheel_fl_spin spin_anim000 fps 30 { 
   blend vehicle_wheel_fl_spin -180 180 
   blendwidth 4 
   delta 
   autoplay 
   spin_anim_fl240 spin_anim_fl120 spin_anim000 
 } 
 // This is the blended sequence which describes how to rotate the rear right wheel 
 $sequence wheel_rr_spin spin_anim000 fps 30  { 
   blend vehicle_wheel_rr_spin -180 180 
   blendwidth 4 
   delta 
   autoplay 
   spin_anim_rr240 spin_anim_rr120 spin_anim000 
 } 
 
 // This is the blended sequence which describes how to rotate the rear left wheel 
 $sequence wheel_rl_spin spin_anim000 fps 30  { 
   blend vehicle_wheel_rl_spin -180 180 
   blendwidth 4 
   delta 
   autoplay 
   spin_anim_rl240 spin_anim_rl120 spin_anim000 
 } 
 
 // This is the blended sequence which describes how to steer the front wheels 
 $sequence steer steer_anim0 fps 30  { 
   blend vehicle_steer -1 1 
   blendwidth 2 
   delta 
   autoplay 
   steer_anim1 
 } 
 // This is the blended sequence which describes how to bounce the right front wheel 
 $sequence wheel_fr_suspension jump_anim_fr0 fps 30  { 
   blend vehicle_wheel_fr_height 0 1 
   blendwidth 2 
   delta 
   autoplay 
   spin_anim000 
 } 
 // This is the blended sequence which describes how to bounce the left front wheel 
 $sequence wheel_fl_suspension jump_anim_fl0 fps 30  { 
   blend vehicle_wheel_fl_height 0 1 
   blendwidth 2 
   delta 
   autoplay 
   spin_anim000 
 } 
 
 // This is the blended sequence which describes how to bounce the right rear wheel 
 $sequence wheel_rr_suspension jump_anim_rr0 fps 30  { 
   blend vehicle_wheel_rr_height 0 1 
   blendwidth 2 
   delta 
   autoplay 
   spin_anim000 
 } 
 
 // This is the blended sequence which describes how to bounce the left rear wheel 
 $sequence wheel_rl_suspension jump_anim_rl0 fps 30  { 
   blend vehicle_wheel_rl_height 0 1 
   blendwidth 2 
   delta 
   autoplay 
   spin_anim000 
 }
 
 // This is the exit animation. Depending on where you are looking it can run difference animations on exiting the vehicle. 
 // You need one of these or half-life will crash when you leave the car 
 $sequence exit1 "car_idle" fps 30 
 // This specifies the players viewpoint when you get in the car. 
 // The rotation MUST be correct or your view will rotate when you get in the car. 
 $attachment "vehicle_driver_eyes" "car.view" 0.00 0.00 0.00 rotate 0 0 -90 
 // This specifes where you end up in relation to the car  when you get out.  
 $attachment "vehicle_driver_exit" "car.body" -20.00 60.00 -60.00 rotate 0 0 -90 
 // Wheel locations. This tells half-life the location of each of your wheels. 
 // Make sure these are correct or you can get very weird results. 
 // Also make sure the distance between the wheels in the X and Z dimension are greater than zero. 
 
 $attachment "wheel_fl" "car.wheel_fl" 0.00 0 0.00 rotate 0 0 0 
 $attachment "wheel_fr" "car.wheel_fr" 0.00 0 0.00 rotate 0 0 0 
 $attachment "wheel_rr" "car.wheel_rr" 0.00 0 0.00 rotate 0 0 0 
 $attachment "wheel_rl" "car.wheel_rl" 0.00 0 0.00 rotate 0 0 0 
 // Not sure if these are used. 
 $attachment "raytrace_fl" "car.body" 7.00 100 15.00  rotate 0 0 0 
 $attachment "raytrace_fr" "car.body" 7.00 100 -15.00  rotate 0 0 0 
 $attachment "raytrace_rr" "car.body" -7.00 100 15.00  rotate 0 0 0 
 $attachment "raytrace_rl" "car.body" -7.00 100 -15.00  rotate 0 0 0 
 
 // These attachments define what animation is run when you exit the car. You need at least one 
 // or half-life will crash when you leave the car. 
 $attachment "exit1" "car.body" 69.43 19.95 28.02 rotate -90 -90 0 
 // These control the location of the gun on the vehicle and where the target points. 
 $attachment "beam_damage" "car.body" 20.00 25.00 15.00 rotate 0 0 0 
 $attachment "muzzle" "car.gun" 10 0 0 rotate 0 0 -90 
 $attachment "gun_ref" "car.gun" 0.00 0.00 00.00 rotate 0 0 0 
 
 $surfaceprop "metal" 
 
 // This is used to specify the entry and exit points created above to half-life. 
 // If you don't have this then the entry and exit information above 
 //   is ignored. You MUST have the vehicle_exit line. The vehicle_entry line is optional. 
 $keyvalues { 
   vehicle_exit { 
     "exit1" "upright" } 
 } 
 $collisionmodel "car_phy.smd" { 
    $concave 
    $mass 800.0 
    $inertia 1.00 
    $damping 0.00 
    $rotdamping 0.00 
 } 


Create a dos window and cd to your hl2/hl2 directory. If you have never used studiomdl before then copy all the dlls from hl2/bin and the studiomdl executable to the hl2/hl2 directory. This is due to a bug in studiomdl in the beta. Now type "studiomdl "path to qc file". You should now have your mdl file.

If you get a smoothing group error then check to see if you only used boxes in the phy model and that each box is assign a different smoothing group.

If studiomdl complains about missing textures then make sure you have imported all the textures into correct locations in the materials/models directory.

You should not get any errors. If you do then you need to fix them before you go on.

Load up the mdl in hlmv. Go to the attachment window and make sure all the attachments are there and correctly located. When you view the attachments in HLMV the red axis should point towards the front of the vehicle and the blue axis should point up. If they don't then change the angles in HLMV until they do, copy the settings to your QC file and recompile. You can also verify your animations in the sequence window. Make sure each wheel rotates correctly and the steering works correctly. Now load it up in hammer, compile your map and drive into the sunset.


Enjoy, Cannonfodder

Personal tools