Creating a New Melee Weapon
In this tutorial we are going to see how to add a new Meele Weapon in the game.
In particular we are going to add a one-handed sword that the Player and NPCs will be able to use. I'm going to use this model made by rubenve.
Creating the Prefabs
The first thing you need to do is to drop your weapon in the scene and apply the material. Once you did that, prefab the weapon, I'll do it as "ChevalierSwordPrefab", we are going to use this prefab as a base for the other ones we need to create.
We are going to need 3 Prefabs for this weapon:
- Item In World
- Weapon On Hand: which is the weapon displayed in the First Person and held in the hands of the NPCs, this will allow for the collision detection.
- Weapon Sheathed: which is displayed on the NPCs when they are not in combat.
We are going to start with the creating the Weapon Item and then the Item In World.
Creating the Weapon Item
To create a New Weapon Item, right click in the Project Window -> Create -> RPG Creation Kit -> Items -> WeaponItem
Name it "[WEAPON] ChevalierSword" and leave it for now, we are going to create the Item In World first. Drop the Prefab we've just made "ChevalierSwordPrefab" in the scene and rename it "ChevalierSwordPrefab_InWorld", Reach for the top bar "RPG Creation Kit -> Create New -> Item In World" a window will open.
Drag and drop the "ChevalierSwordPrefab" prefab we've just dropped in the scene in the "GameObject" field, you can edit the other settings as you may wish, I suggest you leave the default ones. Last thing to do is to setting the "Item Ref" to be the Weapon Item we just created, then click on COMPELTE & CLOSE and make sure to Update the prefab.
Refer to the gif on the right for visualizing the process.
Creating the Weapon On Hand
To create the Weapon On Hand in the easiest way possible load a savegame and equip a One Handed sword (or a 2handed if you're doing it).
Then pause the game and switch to the Scene View, reach the Character Controller and click on the Sword to quickly see in the hierarchy the "hand.R" GameObject, child of the FPS Arms. What we are going to do is to drop an instance of the ChevalierSwordPrefab in the hand, and then manually adjust it until it fits in the FPS hands: