The two previous chapters we overviewed how to create a Weapon and an Ammo object, as well as see what each option does. In this chapter we'll see how to put everything together and make Characters make use of the Weapon and Ammo objects in order to pull, aim and shoot at stuff.
The Character Shooter component is a special component that must be added to each Character that is going to hold a weapon.
Drawing and holstering weapons is done using the Weapon Draw and Weapon Holster Actions. These automatically equip the character with the specified weapon.
The Ammo field is optional and, if none is specified, it will use the default Ammo object defined by the Weapon.
Aiming is the process of choosing a target at which to shoot at. There are multiple aiming types, each addressing requirements set by different types of games. Here is the full list of options available when using the Aim Weapon Action.
Stop Aiming: Used to stop aiming with the weapon. Typically used when releasing the aiming button.
Aim Camera Direction: Aims where the camera looks at. Perfect for Third-Person and First-Person shooter games.
Aim at Target: The target is specified by a Transform object and keeps track of its position.
Aim at Position: The target is specified by a given position.
Aim Muzzle Forward: Simply aims forward, where the character with the weapon is shooting at.
Aim Top-Down Plane: Aims at a direction specified by the projection of the mouse over the plane where the character is. This option is perfect for top-down shooter games.
Aim Top-Down Floor: Very similar to Top-Down Plane, but instead of shooting straight ahead where the eyes of the shooter are, the shot is performed where the mouse position intersects with geometry. This allows to shoot at enemies that are on a lower or upper level than the shooter.
Aim Side-Scroll: Aims at a direction specified by the project of the mouse over the vertical plane of one side of the character. The plane (XY or ZY) can be also specified.
Shooting a weapon is very simple. All that is needed is to use the Shoot Weapon Action. This will instruct the weapon to shoot. Depending on both the currently equipped Weapon and Ammo assets, the shot will be different.
However, there's a second type of shot that requires a different set of Actions: The charged shots.
Charged shots need a wind-up time before being released. An example of a charged shot are grenades, bows, Megaman's ArmGun, etc...
To start charging a shot you need to use the Weapon Start Charged Shot. To execute a charged shot you'll need to use the Weapon Execute Charged Shot.
Receiving damage is an essential step in any game where any kind of shooting is involved. There are two ways to deal with damage output: The first one is using the built-in Action Lists provided by each Ammo asset. When shooting with any raycast or trajectory-cast projectiles, the Invoker will always reference the targeted object.
However, this does not give enough control. To solve this, there's the On Receive Shot Trigger, which is executed any time it received a shot. These shots can be filtered by weapon type and shot type (Any, Normal or Charged).