Weapons in the project are divided into three groups:
shields, melee and ranged.
There is legacy 'BowItem' which is its own class but bow can
also be created from 'RangedWeaponItem'.
For now 'BowItem' is a separate entity and it has its own system.
Shield and melee weapons are pretty straightforward and they share similar properties: they have melee damage and reach plus block resistance used when blocking and block
penetration used when attacking.
Shield and melee weapons also hold IK values for usage if / when holding with both hands.
Stamina reduced on block can be assigned on per - weapon basis and by default shield don't reduce stamina when blocking, other weapon does.
If stamina gets too low, a block will be broken.
Ranged weapons are, on the other hand, more complex and implement more features.
Along with shared weapon item features ( melee damage and reach, left hand IK etc.. ) ranged weapon divides into 5 groups:
Sidearm, Machinegun, Rifle, HeavyMG and RPG.
Sidearm is a one-handed weapon mode, Machinegun and rifle are ranged weapon mode and HeavyMG and RPG are heavy weapons mode.
Every ranged weapon requires fire position to be set in 'FirePosition' field ( transform actually – it holds fire position and fire direction ).
'Aim transform' direction of weapon to which player is aiming – usually that is fire transform also, but if not, assign separate transform as aim transform.
If aim transform is left empty, the fire transform will
automatically be assigned to it.
Set 'Burst Mode' of weapon ( fire rate at a click: Single, Burst, Auto ) and set what ammunition weapon is using.
Next, assign / tweak the list of ranged weapon values like ranged damage, spread ( accuracy ), number of shots before reload, shoot interval, range.
'Range' is used if 'Raymarching' option is disabled. It is the length of instant ray that is thrown from weapon fire position upon firing.
If 'Raymarching' is set to true, weapon bullet behaves like a projectile, that is, it travels by assigned speed starting from weapon fire position influenced by gravity value.
Also if 'Raymarching' is enabled, more options appear:
projectile speed, projectile gravity influence, projectile object ( you can assign mesh that will represent bullet or some other type of projectile) and option to destroy that object on impact.
Note that projectile object can contain a script that can
execute some effect at 'OnEnable()' and 'OnDestroy()' method.
'Ranged weapon' also contains the field for:
- 'Hit Mask' – layers that weapon projectile interacts with,
- 'Hit Reaction Override' – you can override hit reactions on per weapon basis, attack type ( if 'HitReactionType.Animated' is set in 'overrider', you can assign attack value – that is a value that, like melee attacks, start the animated hit reaction ).
- 'Num Rays Thrown' - assign a number of rays thrown per weapon. Usually, weapons shoot only one ray but some weapons, like a shotgun, shoot multiple rays representing
buckshot projectiles.
- 'Minimum Sound Interval' is fire sound limiter. If needed, you can assign here minimum sound interval if the fire rate is too high and cause awkward sounds.
Also, there is an option to assign particle effect systems to play on impact.
- 'ImpactEffects' - assign root particle system game object to 'ImpactEffects' field.
- 'Impact Hit Force' - a force that will be applied on hit object ( if it has non-kinematic rigidbody ) you can set in 'Impact Hit Force' field.
- 'Ammo Object' - ammo clip or ammo magazine that will be
ejected, respawned and set into weapon can be applied in
'Ammo Object' field.
Upon reload, on event 'GrabNewMag', the new clip will spawn into 'Left Hand Holding Transform' ( 'PlayerControlBase.cs' ) and at event 'Reload' it will be set into a weapon. The old clip will be ejected at 'EjectClip' event.
'Ammo Object Control Bone' is the option to set animated transform ( bone ) that controls new ammo magazine.
'Cameras' are a list of transforms that will hold a camera when the player is aiming with a ranged weapon.
When aiming, the user can with the mouse wheel, switch camera position to one of the assigned cameras. It can switch from camera to camera depending on input ( mouse
wheel up or down ).
'RangedWeaponItemAdvanced' is a class derived from
'RangedWeaponItem' and has additional properties.
It can hold multiple additional fire positions ( multiple barrels ) that can be shot all at once all fire in order one by one.