Creating a New Melee Weapon

From RPG Creation Kit
Jump to navigation Jump to search

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

"ChevalierSwordPrefab" The base Prefab of our weapon.

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. Also create a folder named "Chevalier Sword" so that we put all the related assets in this folder.

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.

Weapon Item & Item In World

GIF that shows the creation of the Item In World for the ChevalierSword we are creating.

To create a New Weapon Item, right click in the Project Window -> Create -> RPG Creation Kit -> Items -> WeaponItem. However, it is always better to duplicate an existing weapon of the same type as the one you're creating, because you'll skip all the configuration you otherwise have to do every time, but for this time let's create it from scratch.

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), I'll equip the Iron Longsword.

Now 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, name it "ChevalierSwordOnHand" and then manually adjust it until it fits in the FPS hands.

You can disable the Iron Longsword to have a better view. (If you switch to the Game View you'll see that the hands are always on top of the sword, that's normal - we'll get to it shortly).

Once you're happy with the position click on the Iron Longsword and look at the Inspector, then and Copy the "WeaponOnHand" Component and paste it on the "ChevalierSwordOnHand" GameObject, in this GameObject, click on "Debug Weapon" and set the array length of "Hit Marks" to be 0.

Now we need to create the hitmarks, which will tell us where the sword can damage other entities. Ggo ahead and create new Empty GameObjects inside the sword, place them for all the length of the blade (or the range you want your weapon to be) each one a bit distanciated from each other and once you're done add all those to the Hit Marks array.

You will see blue spheres appearing on the Blade of the Sword, those are the represention of where the hitmarks, you may want to tweak them a bit. The last thing to do is to add an AudioSource component to the new sword and set assign it to the "WeaponOnHand" AudioSource field. Tthen we're done - just Prefab the "ChevalierSwordOnHand" and you can stop the game.

Refer to the video below for visualizing the process:

Creating the Weapon Sheathed

The last prefab we have to make is the one of the weapon sheathed, while it is equipped on the NPCs but not in their hands.

One handed weapons are sheathed on the left side, while two handed weapons and bows are attached on the back.

To visualize this Open a Prefab of any AI. I'll open the "[AI] CityGuard001" prefab by double-clicking on it.

GIF that shows the process of creating the Weapon Sheathed Prefab.

Scroll down in the hierarchy to "Unity compilant skeleton" and look at the childs:

  • hips: is where one-handed weapons are attached.
  • chest1: is where two-handed weapons, bows and ammo are attached.

So drop a "ChevalierSwordPrefab" inside the hips, then place it as you'd like the NPCs to have it while it is sheated. Then rename the prefab to be "ChevalierSwordSheated" and save it as an Original Prefab.

Then delete it from the Prefab you opened.

To visualize the process, refer to the gif on the right.

Editing the Weapon Item

Now that we have all the prefabs, we can edit the "[WEAPON] ChevelierSword" Weapon Item.

Click on it and scroll down in the Inspector, then click on "Configure Item".

Set the ID to be unique, the name and the other settings as you'd like.

Setting the World Model, WeaponOnHand and WeaponSheathed prefab we've created.

Before getting to the others, set the World Model - WeaponOnHand - WeaponSheathed fields:

  • World Model: will be the prefab we've created "ChevalierSword_InWorld".
  • Weapon On Hand will be the prefab we've created "ChevalierSword_OnHand".
  • WeaponSheathed: will be the prefab we've created "ChevalierSwordSheathed".

For the other settings, you can decide them, but you should put as:

  • WeaponType: BladeOneHanded
  • FPS Animator: FP_OneHanded_R
  • TPS Animator: TPS_Base

Then scroll down to attacks, here you have to define the attacks the weapon can do.

For a One Handed weapon there are 4 Attacks and 1 Charged Attack, so you should have:

  • Attack Types: 4
  • Charged Attack Types: 1

On the bottom you'll have to configure the attacks:

1f1 .png

  • Attack Type Index always needs to be the Element number, so in this screenshot we're editing Element 0, so Attack Type Index will be 0. The next one will be Element 1, so Attack Type Index will need to be 1.
  • Base Damage is the damage this swing will deal.
  • Stamina Amount is the stamina consumption that will occur to the attacker while swinging.
  • How Many Hits Can Sustain: tells how many enemies we can hit with a single swing, it should always be at least 1, otherwise the weapon will not hit anyone.

You can look at other One Handed weapons like "IronLongsword" to see how it is configured.

Then you have to do the same thing for the WeaponChargedAttacks.

At this point we're done, click OK to save, then reach for the topbar and UPDATE THE DATABASES, to do that reach for the top bar "RPG Creation Kit -> Update All Databases".

Now you can drop the "ChevalierSwordInWorld" wherever you want it place it. Do it now, I'll drop it in the Cell "Virrihael(0,1)". After dropping it in the scene look in the Inspector for the ItemInWorld Component, right click on the Component's name and select "Regenerate GUIDStr" that will make that instance of the sword unique throughout the whole game.

With that out of the way, we can load a savegame from the main menu and reach the point where we dropped the Sword. You can take it, drop it, equip it and you can make NPCs equip it as well.

Final Result

Cnmlwfr 1.png

Cnmlwfr 2.png

Cnmlwfr 3.png

Vv 1vv 1.png

Files & Downloads

You can download all the files made in this tutorial at this link.

Make sure to read the LICENSE.txt file!