Thread: [Tutorial] Func_vehicle with models

Results 1 to 5 of 5
  1. #1
    Super moderator Hezus's Avatar
    Join Date
    Aug 2001
    The Netherlands

    [Tutorial] Func_vehicle with models


    This tutorial shows you how to make a func_vehicle and use a model for a car! It's quite tricky to get it working, but if you follow these steps it should all work!

    PART I: Setting up the scripts
    The current version of SC has a func_vehicle_custom Angelscript (in ../svencoop/scripts/maps/) but you'll need some more to get it working properly. First you'll need a script to load the func_vehicle_custom.
    1. Copy the following code in Notepad and save it as "".
    #include "func_vehicle_custom"
    void MapInit()
    	VehicleMapInit( true, true );
    2. Put the '' and '' in ../svencoop/scripts/maps/vehicles/ . You can use a different name for 'vehicles' but make sure it's saved in this location.

    3. Open Notepad and create a CFG file for you map. I'll name mine vehicles.cfg, since my map will be called vehicles.bsp. The CFG and BSP files should have identical names. You can add all kinds of start conditions to the CFG file but make sure this line is in there, so it'll load the Angelscripts.
    map_script vehicles/vehicles
    PART II: Setting up the map
    1. Before you load your map, set up the FGD for vehicles, located in ../svencoop/scripts/maps/fgd/.

    2. Copy your car model file into ../svencoop/models/vehicles/ (or different name, but same location).

    2. Create an item_generic and name it 'car1_mdl'. Select your car model in 'Custom Model". IMPORTANT: Make sure the angles are set to 0 0 0.

    3. Create a flat block roughly the shape of the car you're going to use. I moved the car model on top of the brush to see if it matched the shape. Keep it simple so players don't collide with the brushes while driving. Apply NULL texture to all sides (use zhlt.wad). This will make it invisible. IMPORTANT: Make sure the front of your brush is faced WEST WARDS (looking from the topview). Make sure the angles are set to '0 0 0'!

    4. Turn it into a func_vehicle_custom. Set it's name to 'car1'. If you are using JACK, then you'll have to manually add 'targetname' 'car1' by hitting SMARTEDIT (JACK has trouble loading multiple FGDs with base entries such as targetnames).

    5. In the center of the vehicle brush create a block with the ORIGIN texture on it. Now slide this block down so it's center (X) is on the ground below it. It needs to be there because the item_generic has it's origin in the same location. Now select the ORIGIN brush and the func_vehicle_brush and tie them together.

    6. Create a block with AAATRIGGER texture and make it a func_vehiclecontrols and place it where the player is sitting to steer. Set 'Vehicle Name' to 'car1'. It might look like this now:

    7. To tie the brush and model together create a trigger_copyvalue. Tags the flags 'Constant', 'Start on', 'Multiple destinations'. 'Source Entity' should be 'car1' and 'Source Key' 'origin'. 'Destination Entity' is 'car1_mdl' and Destination Key is 'origin'. Make a 2 copies of the trigger_copyvalue and change the Source and Destination Keys to 'angles'. In the first copy tag 'Don't use X' flag. On the second copy tag 'Don't use Z', 'Don't use Y' and 'Invert Source' flags. This makes sure that the car model will align itself properly with the func_vehicle when moving on the X axis (going up and down slopes).

    This will now constantly sync the center and the angles of the brush and the model.

    8. Compile the map (make sure it's called the same as the CFG file!) and go for a test drive! If your model showed up right, then you are one lucky duck. Chances are, however that your car model drove backwards or sideways. This is because the model isn't facing west-wards by default. The angle needs to remain 0 for it to work properly, so that means we'll need to fix the model file.

    PART III: Fixing the model
    1. Look at your model from the Top view and determine the angle it needs to be rotated (90, 180 or 270) for it to face westwards with an angle of 0. Remember this value.

    2. Open SoloKillers HLMV (default HLMV or Jed's HLMV works too). Go to Tools -> Options and set the paths to studiomdl and mdldec (download them here). Then go to Tools -> Decompile Model and select your model. Set up a game config (SC) and press OK. This then brings up a log where you can see if your model has been compiled.

    3. Go to the folder where it decompiled your model and find the corresponding QC file. Open it with Notepad. Now add this line to the file (under $cbox or $eyepostion).
    $origin 0 0 0 90
    The value '90' is a 90 degrees rotation so you might need to change that to 180, 270. -90 should work too. Save the QC file.

    4. Go back to the Model viewer and go to Tools > Compile Model. Now select the QC file we just edited and click OK. It should now compile the model. Make sure you copy this fixed model into the right folder in ../svencoop/models/..

    5. Restart Hammer/JACK and check if the car model is facing westwards now. If you have try a different rotation, repeat the steps above. Make sure you restart Hammer/JACK because it precaches the models before loading, so it won't show the updated version right away.


    Some sidenotes:
    - The origin and angles are constantly updated but have a small delay. Therefore the model will always lag behind a bit. The faster you set the vehicle the more this becomes apparent. I'd advice a max of 300 speed to keep it within reasonable boundries.
    - Currently going up and down ramps or driving off cliffs will cause the func_vehicle to float in some conditions.
    Last edited by Hezus; 08-03-2018 at 08:47 AM.

  2. #2
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    U.S. West

    Re: [Tutorial] Func_vehicle with models

    I think the model lagging can be fixed with MOVETYPE_FOLLOW, but that requires a script to set up the follow target. Vehicles are laggy in general though so limiting max speed is still a good idea.

    As for the ramp angle, enabling the "invert source value" spawnflag on a trigger_copyvalue for the X angle (or wtv pitch is) should do the trick.
    Last edited by w00tguy123; 07-03-2018 at 11:52 PM.

  3. #3
    Super moderator Hezus's Avatar
    Join Date
    Aug 2001
    The Netherlands

    Re: [Tutorial] Func_vehicle with models

    Quote Originally Posted by w00tguy123 View Post
    As for the ramp angle, enabling the "invert source value" spawnflag on a trigger_copyvalue for the X angle (or wtv pitch is) should do the trick.
    That works, thanks! I'll add it to the tutorial.

    Now, there's a new problem. It seems the func_vehicle starts to float upwards once it's coming off a ramp. I guess it's origin doesn't quite align with the floor properly. Same when you drive off a cliff, it'll just float. Seems it copies the angle of the slope below it, but the func_vehicle has no gravity properties of it's own. I thought maybe it was because 'height above track' but that doesn't affect it at all.
    Last edited by Hezus; 08-03-2018 at 08:48 AM.

  4. #4
    REE3 The303's Avatar
    Join Date
    Jul 2015

    Re: [Tutorial] Func_vehicle with models

    Cool stuff, For the standard brush-based func_vehicle without a model I found out you can use "CLIP" brushes as a part of it to define and block off complex brush details so you don't get hung up on things like say a handlebar or steering wheel. The CS1.6 version is pretty much identical only does not use the "path_track" i take it? There is a guide for the classic CS1.6 version here:

    EDIT: It appears adding a "path_track" moves the vehicle into position and the second path can change its orientation depending on its position relative to the first however unlike the CS1.6 version you do NOT target the first path to loop back to the second or else the whole thing flips on the wrong axis entierly.

  5. #5
    Registered User
    Join Date
    Mar 2018

    Re: [Tutorial] Func_vehicle with models

    Awesome tutorial Thanks for sharing!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts