Create Weapons

First, Create The Data

To create weapons you need to create a new DataEntity that derives from WeaponBase. In Prodigy this is WeaponMelee, WeaponRangedProjectile or WeaponRangedHitscan. You can always create your own classes to add data and override behavior.

Once created, you'll be able to reference your weapon anywhere else via dropdown. For instance in the ItemLootTable class where you define starting items for a Player, or for Loot Crates, or in the Merchant Items For Sale space.

You are responsible for making sure that all of the data and references to prefabs are properly set and available - since now other classes are going to be reading this weapon data preset and acting on that information. Every variable on these classes is used in very specific ways, so pay attention to each one and make sure it's correct and valid.

Weapon Concepts

Weapons are designed to have a prefab that shows up in the world as a cool rotating item you can pick up but no fancy weapon components on it. Separately, there's a prefab for the object you want to be placed into your character's hands and this prefab has the weapon components on it.

When you attack with a weapon, the AgentEquipment is going to be reading the inputs from the Player and if you're firing then it runs the Fire method on the Weapon component in it's hand. It doesn't care much else about what weapon is there, it just tells it to do the thing. Once the weapon gets this call it will work with the vault data back end to handle firing, vfx, sounds, recoil, cooldowns, etc.

When it gets mounted onto the avatar the system will reference a few datapoints in order to orient it correctly. This is because all avatars have various orientations of their bones and it deeply affects the rotation of objects set as their children. The WeaponMountData on the AvatarDefinition will customize how this orientation is solved but it needs input from you to get the right values.

WeaponBase

Most of the properties are self explanatory, but there are a few we'll clarify.

PrefabAsEquipped and ArtPrefab

Normally when items are spawned into the world space the system will use the base item field ArtPrefab. However when weapons are spawned for the purpose of being mounted to the character it will instantiate the PrefabAsEquipped object instead, and mount it to the character.

This is done so there can be runtime components attached to the weapon where we can manage references to spawn point, change how we handle VFX, etc.

WeaponMountData

This is an important part of the Weapon that tells the IK system where to mount it and how to operate IK.

It's nigh impossible to dynamically put something into a rigged character's hand perfectly without help. Every rig's hand is a different size, the bone has different orientation, and we have no way of knowing which direction is which or where the 'palm' really is. This is a limitation of doing weapons this way. If you need them perfect, then you need to roll back to animations where you can control them more precisely.

However doing it dynamically gets very close and offers a lot of advantages!

The data here (in WeaponMountData) is in regular units, and is easiest to manipulate if you hook up the fields, enter play mode and mount the weapon, then adjust the variables in the Vault Dashboard at runtime since they'll persist when you leave runtime. You can use GameSettings Debug Weapon Mounting toggle to make the database changes will be constantly remounted at runtime so you can adjust visually and it will persist.

When creating your weapons you'll want the prefabs to be oriented so that Z+ is forward and Y+ is up. The same goes for your weapon sockets on the character prefab, make sure the axi on that object parented to the hand are Z+ pointing straight out from the arm, Y+ is straight up, with the thumb. Keeping with those standards will let all weapons be mounted on all characters since they will have a common direction system for the hands.

Impact Effects (Layers and Tags)

Weapons use OBJECT TAGS to determine the type of object being hit. Just regular Unity Tags, nothing special. We lay out a few like "Metal, Dirt, Rock" etc... but you can change these as you see fit. The Impact map for a weapon will connect VFX prefabs and sounds to these tags and you can change them per-weapon so that every weapon can make different sounds when it hits things.

Weapons use OBJECT LAYERS to determine whether or not it can hit it or should hit it. Most of the time weapons will be looking for the primary environment layer and the agent layer. Some layers are excluded from interacting with each other as you can see in the Project Settings > Physics > Collision Matrix window.

While these are good settings that should work for most use cases, you can always change them to suit your game's design.

Last updated