Mounted Guns

- By Raeven0
This tutorial was last updated on Aug 4, 2005.

A mounted gun is what was seen in the last HL2 level before Nova Prospekt:

The gun can be grabbed and used instead of a normal gun. It can't be moved, but it can turn in place to aim at other locations. This is the sort of gun we'll be making; later in the tutorial, we'll look at making the mounted gun shoot rockets, lasers, and "mortar" shells (they seem more like nukes to me, and the effect is really cool).

The basic player-controlled mounted gun

The most basic player-controlled mounted gun consists of a func_tank brush and a trigger volume in which the player must stand to operate the gun. I've made a simple gun and trigger volume already:

The trigger_multiple needs a name, and it needs its flags marked to allow "Clients." The func_tank needs to have its Control Volume set to the trigger_multiple, and it needs its "Controllable" flag set. Also, you'll want to modify the tank's Bullets property, because it defaults to "None."

Note that the func_tank absolutely must face EAST in the editor. This is RIGHT in the top and side views, and won't appear in the front view. The func_tank will automatically reorient itself to face in the direction specified by its Pitch/Yaw/Roll. If you want a gun to point north in-game, for example, have it point east in the editor, then set its Yaw to 90.

Essentially, that's all there is to making a basic mounted gun. Bullets will come from the entity's origin, the same point around which it pivots; to change the point from which bullets fly, modify the Barrel Length, Barrel Horizontal, and Barrel Vertical, which move the bullet-firing point forward/backward, left/right, and up/down, respectively.

Func_tank has a good deal of other properties that you can play with. Try them out!

Making the gun NPC-controllable

NPCs, unlike players, need a point at which they must stand to control the gun.

In this scenario, the Combine soldier will happily run around in the area behind the func_tank, because he has nodes there. If he comes across the gun, and he's not busy shooting at someone, then he'll grab the gun and happily fire at all enemies he sees until he gets distracted (i.e., shot from behind).

All he needs to man the tank is an info_target (other entities may work) near it. The tank must have its "NPC Controllable" flag set, and its "NPC Man Point" set to the name of the info_target. Also, having ground nodes (info_node) near the info_target would not be a bad idea, as the NPC needs to be able to reach it in order to man the tank.

Making the gun shoot a particular target on its own

Gun targets can't be declared in the properties; they must be defined by inputs. Check the tank's "Active" flag and send it one of the following inputs, where the parameter is the target entity, target position, or target direction.

- SetTargetPosition x y z (coordinates)
- SetTargetDir x y z (vector)
- SetTargetEntityName target/classname

The func_tank will track and fire at the specified position, in the specified direction, or at the specified target. The Activate and Deactivate inputs will start and stop the tank, respectively.

Model-based guns

The easiest way to make a model-based gun is to texture the func_tank with tools/toolsinvisible, then place a prop_dynamic at the tank's center. The prop_dynamic can then be parented to the tank, giving the impression that the model is being controlled when in fact it's just moving with an invisible tank.

The model gun seen in the HL2 coast level is models/props_combine/bunker_gun01.mdl. In order to give the effect of the gun jumping up whenever it gets a controller, the func_tank had the following outputs:

- output OnFire target turret_4_model input SetAnimation parameter fire
- output OnGot[Player]Controller target turret_4_model input SetAnimation parameter activate
- output OnGot[Player]Controller target turret_4_model input SetDefaultAnimation parameter idle delay 0.1
- output OnLost[Player]Controller target turret_4_model input SetAnimation parameter retract
- output OnLost[Player]Controller target turret_4_model input SetDefaultAnimation parameter idle_inactive

--where turret_4_model is the name of the prop_dynamic. [Player] indicates that the output in question occured twice, once for Controller and once for PlayerController; I condensed these into one output to save space.

The func_tank therefore has nine different outputs just to make the gun look good. These outputs set the model's animations to the appropriate fire or idle animations built into the model. Not all models will have these animations.

Guns attached to models

In HL2, the APC (that annoying silver vehicle we'd all like to drive but can't) often had a gun mounted on its side. This was done via a func_tank's Gun Base Attachment property (as well as the five properties that complement it). With this property, the func_tank aims and fires not from itself, but from an attachment on the specified entity.

The aforementioned gun model, for instance, has an attachment point called aimrotation that could be specified as the Base Attachment. It also has an attachment point called muzzle that could be used as the Barrel Attachment. This would make it seem more like the model itself is firing instead of the func_tank as the aiming and firing are done from specific points on the model.

You can see all of a particular model's attachment points by opening the model in HLMV (accessible from the Source SDK menu) and viewing the "Attachments" tab.

The other four properties, two Gun Pitch and two Gun Yaw, make the model gun even better by modifying the gun's pitch and yaw in a specific way instead of just moving the entire model. For instance, the aforementioned gun model has a stand on it; however, the stand remains static even though the gun rotates. This is because:

- the tank is parented to the model entity, not vice versa;
- the tank's Yaw Pose Param is set to aim_yaw;
- the tank's Pitch Pose Param is set to aim_pitch.

These latter two options allow the tank to affect the model itself using the specified parameter. These parameters are built into the model, and individual models may need different parameters. You can view a list of available parameters by opening the model in HLMV (accessible from the Source SDK menu) and viewing the "Sequence" tab. The available parameters are in the too-small drop-down menus on the right side of the interface.

Other types of mounted guns

You can use a different classname than func_tank to get a special effect.

Note: The accuracy and bullet type properties only affect func_tank and func_tankpulselaser. The bullet damage properties only affect func_tank, func_tankpulselaser, and func_tankrocket.

Func_tankairboatgun - Specify the targetname of an airboat, and the tank will automatically attach itself to the airboat in the appropriate spot. This entity fires airboat laser bursts.

Func_tankapcrocket - Cannot be aimed properly by players or NPCs. Give it a valid target and it will fire APC rockets high into the air that will soon home in on their target. Interestingly, this entity is invisible and non-solid in-game.

Func_tanklaser - Fire a laser instead of a bullet. Fun! Requires an env_laser entity; this env_laser will be moved to the gun's barrel whenever the gun is fired.

Func_tankmortar - Fire what's referred to as a mortar shell 1024 units into the air. The mortar shell lands on the target and explodes in a very cool display of particles, sprites, and vaporized enemies. (Must... resist urge... to make comment... about bombing sandy nations...)

Func_tankphyscannister - Requires another trigger_multiple, flagged to detect "Physics Objects." This entity will activate a random physics_cannister entity within its defined Cannister Volume. (The misspelling of "canister" is not my fault, I swear.)

Func_tankpulselaser - BUGGY ENTITY! Launches a laser sprite at a target at a specific speed. The laser has the tendency to bounce off walls (though it is not visible when it does this), and it makes a normal bullet sound when it hits something because the WAV that's supposed to play does not exist. The laser can set things on fire, though.

Func_tankrocket - Launches RPGs (rockets) instead of bullets.

Func_tanktrain - Combination of func_tank and func_tracktrain: a moving entity that shoots the player.

Mounted guns in HL2DM and CS:S

Mounted guns aren't fully supported in HL2DM. A player using a mounted gun continues firing his normal gun, even unto making bullet holes, but doesn't use any ammo nor do any damage. The player must be wielding a grenade or SLAM in order not to see this strange effect.

Furthermore, a normal func_tank's tracers aren't visible in HL2DM, and the bullets don't leave bullet holes (even though the bullets from the player's gun do).

The mounted gun entities do not work at all in CS:S.

This tutorial can easily be modified to work as a standard mounted gun for HL2DM and CS:S. Replace the two func_rotatings--that is, the base and the barrels; delete the chaingun entirely--with very small toolsnodraw-textured blocks, and parent your normal tank to them (if it's func_tank or any variation thereof, make it func_brush first).

In order for the turret to actually do damage, there will need to be an env_laser/info_target pair in front of it, parented to the old tank, which is now func_brush or prop_dynamic. The env_laser can be made invisible (check the Brightness property). It will need to be activated every time a bullet is shot.

Still need help? Ask your questions in one of our HELP FORUMS
Post A Comment
Email: Links Not Allowed In Comments
What is the capital of France? Need Help?
Ulver - Oct 21, 2006
How to make the func_tank fire via an input? And hw to combine that dual chaingun with the func_tank ?
Raeven0 - Jul 28, 2006
Wildseven, mounted guns shouldn't do that; it sounds more like a rare graphics bug that occurs when testing a map directly from Hammer. Try loading the map normally, by running the mod and writing 'map my_map' in the console.
wildseven - Jul 28, 2006
everytime i make a mounted gun the whole screen goes black when testing, any help? :S
Raeven0 - Apr 14, 2006
Yarly, to my knowledge, the func_tank entity doesn't work in DOD:S. You'll have to use [url=]this method[/url] instead.
yarly - Apr 14, 2006
Do these mounted guns work in Dod: S ?
mici mico - Feb 11, 2006
There is sdk_d2_coast_12.vmf map in the SDK which can be used to study this kind of entitiy.
All original content 2006 All Rights reserved. All files property of their rightful owners.
Get Firefox! Get Thunderbird! Get Notepad++!