# Vehicle Weapons

The **Weapons** component provides key weapon functionality to a vehicle, and a vehicle should have this component added to the root transform.

### Accessing Gun/Missile Weapons

The Weapons component gets all the weapons on the vehicle at the start as well as any loaded onto the vehicle during gameplay and stores them in the *Gun Weapons* and *Missile Weapons* lists. You can access them like so.

```
// Get the list of gun weapons
List<GunWeapon> gunWeapons = myWeapons.GunWeapons;

// Get the list of missile weapons
List<MissileWeapon> missileWeapons = myWeapons.MissileWeapons;
```

### Selected Target

The *Weapons Target Selector* is the target selector that defines the target for gun lead target calculations and missile locking, and also defines the target that an AI will attack.

Set it in the inspector of the **Weapons** component.

You can access the selected target on the Weapons component like so:

```
// Get the selected target
Trackable selectedTarget = myWeapons.Target;
```

### Turrets

The **Weapons** component accesses and stores all the turrets on the vehicle and aims them at the *Turret Target Transform* defined in the inspector.

With the *Turrets Mode* setting, you can define how turrets on the vehicle are handled:

* Independent - the turret is left to its own devices to acquire targets and fire at them
* Manual - the turret is aimed and fired by the vehicle
* Auto - the turret target is provided by the *Weapons Target Selector* but it decides when to fire

### Lead Target Positions

When a target is moving very fast across the line of sight, projectile weapons must be aimed ahead of it to hit it. Exactly where to aim is calculated as the lead target position. You can access the lead target information on the **Weapons** component like so:

```
// Get the lead target positions for each gun weapon in the Gun Weapons list
Vector3[] leadTargetPositions = myWeapons.LeadTargetPositions;

// Get the average lead target position, providing the target's actual position and velocity
Vector3 averageLeadTargetPosition = myWeapons.AverageLeadTargetPosition(targetPosition, targetVelocity);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vsxgames.gitbook.io/universal-vehicle-combat/weapons/vehicle-setup/vehicle-weapons.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
