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.

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

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, then we're done - just Prefab the "ChevalierSwordOnHand" and you can stop the game.

Refer to the video below for visualizing the process:

<youtube>https://www.youtube.com/watch?v=wEpL6Rlp9Io</youtube>