# Weapon

## Description

The *Weapon* component is the main component in *FP Motion* related to weapons, its primary purpose is to make an object into a gun by allowing it to shoot, have ammo, and other things.

This component also holds the information on what camera and weapon state file the object it's placed on uses allowing for much customization.

{% hint style="info" %}
Guns in the asset all have this component attached to them.
{% endhint %}

## How does it work?

In *FP Motion*, a weapon has two main things that it can do, those being shooting and reloading; thus, the *Weapon* component allows weapons to do just that, and in doing so, it makes use of the event system that the asset has in place.

For that purpose, the component subscribes its functions to the **shoot**, and the **reload** events.

Whenever the shooting event gets invoked, it makes sure that the weapon can shoot by making a fire rate calculation (time since last shot).

## Usage

The way to use this component is by placing it on the weapons that the player can wield; this only works if the [Player Events](https://unfinishedstudios1.gitbook.io/fp-motion/components/player-events) component and other *FP Motion* scripts are in place.

*FP Motion* also has a separate Projectile Spawner script that enables the guns in the asset to shoot 'projectiles.'

Another thing to keep in mind is that we usually add weapons as children of a Holster object to allow the player to switch between them, but some games might not require this feature.

## Tweaking

When changing how a gun in *FP Motion* functions, it is essential to look at simple fields like `fireRate` or `ammo,` but it is also crucial to look at the States fields.

These two fields, `cameraStates` and `weaponStates,` hold the *States* files that change how the gun and the camera behave in the different states.

Other important things include the fire rate and ammo per magazine fields.


---

# 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://unfinishedstudios1.gitbook.io/fp-motion/components/weapon.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.
