Difference between revisions of "Creating a New Melee Weapon"
Line 5: | Line 5: | ||
== Creating the Prefabs == | == Creating the Prefabs == | ||
[[File:Cnmw1.png|thumb|229x229px|"ChevalierSwordPrefab" The base Prefab of our weapon.]] | [[File:Cnmw1.png|thumb|229x229px|"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. | 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: | We are going to need '''3 Prefabs''' for this weapon: | ||
Line 17: | Line 17: | ||
== Weapon Item & Item In World == | == Weapon Item & Item In World == | ||
[[File:Cmwg1.gif|thumb|GIF that shows the creation of the Item In World for the ChevalierSword we are creating.]] | [[File:Cmwg1.gif|thumb|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 | 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. | 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. | ||
Line 43: | Line 43: | ||
== Creating the Weapon Sheathed == | == 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. | |||
[[File:Cmwg5.gif|thumb|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'''". |
Revision as of 16:35, 12 March 2022
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. 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
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.
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".