Development Pt.2

Development Pt.2

Back from nightsift, with stamina replenished after some sleep, I can continue with development. 3 days off ahead of me, so wohooo.

I’ve been thinking during my shift about last post, and realized it would be good idea to talk a bit about naming convention. It is not an issue at this stage, while having very few object types, but it will help to avoid a lot of headaches at later stages. Looking for specific object in 100 objects named “TestObject001” to “TestObject100” is not best way to go. I like to use simple naming conventions, like t_ for textures, dt_ for data tables, sk_ for skeleton, skm_ for skeletal meshes, sm_ for static meshes…etc. For an instance, “t_sword_steel” and “sm_sword_steel”, so I’ll know this texture belongs to this object, and it is also makes refering to objects much easier as well. Ok, let’s jump back to UE4 engine.

So now, when picking objects and simple inventory is implemented, it will be good idea to make use of them. From previous post we know that object is simple collection of variables that is being moved between world and character’s inventory (for now). So, I’m going to approach using items same way as I did for picking items. Now, when all information about picked object is stored in inventory slot, I can use it to use or equip item. By clicking on item, it will extract required information and use item (or move it to equipment slot in case of armour or weapon).

So basically we are still moving our collection of variables between inventory and equipment slots. “itemType” variable is used to check type of the object, and based on its type I can execute different functions. We don’t want to end up equipping iron bar or stone as a helmet. If object type is “armour” or “weapon”, it’s going to check “itemSlot” variable, which defines in what slot item should be quipped. Object in inventory is then destroyed. If object is of other type, it will do something else.

Nah, just realized we want to swap equipment items as well, so I need to modify this function a bit. But core idea stays the same.

Now it is done. So if there’s item of any class in, let’s say, helmet slot, and we want to equip helmet from inventory, it will move equipped helmet to inventory, and then equip helmet from inventory.

So that’s the basic function logic for equipping and using items. Same function logic is used to unequip items, with one exception only. If unequipping items, we need to check if there’s space in inventory first. If inventory is full, character simply can’t unequip item. It seems that there shouldn’t be any issues with switching items, since we are moving one item from, and on item to inventory. Hovewer, there are som exceptions, like 2 handed weapons. Let’s say my character has sword in primary hand, and shield in secondary hand, and I wan’t to equip new super-awesome 2 handed sword I just found. In that case we are moving 2 objects to inventory (from both hands), but only 1 object from inventory. So if inventory is full, equipping 2 handed weapon in this case should not be possible. Ok, I’m just talking about nothing now, let’s jump back at prototyping.

Well, now I need new UI widget for equipment window, something simple for testing purpose. In this case I’ve inspired myself by modern video games, where instance of player character is being rendered inside inventory/equipment window in real time.

Simple equipment window with few slots and a player character instance being rendered in the center of equipment window. There’s some antialiasing issue on the rendered character, but it should do the job for now.

Took an inspiration for equipment window from Conan Exiles video game. I’ve actually learned a lot thanks to the Conan Exiles DevKit provided by Funcom, as well as from watching many tutorials provided for free by other professionals (Jackson from TitanicGames is my favourite). But remember, copying and pasting chunks of code is strictly no-no, tutorials should serve learning purpose, for one to understand principles so one will be later able to use knowledge to create own art or code.

There are 2 more things I want to do before testing. Character render inside equipment window should represent player character in the game world, while character in the game world should change appearance based on equipped armour.

Logic behind swapping models on segmented character mesh. i.e. get item from torso slot, if there is any item in the slot (IsValid?), it will get “skeletalMesh” variable and use it to set skeletal mesh for torso. If there is no item in the slot, it will set base mesh as a skeletal mesh for the torso. Character instance rendered in equipment window can take input from player character or directly from equipment slot (what would be more logical, since character instance in equipment window exist only if equipment window does).

Well, there’s actually one more thing I want to do before finishing this post, to close this “inventory episode”. So while messing with inventory system, I’m going to add one more thing, which is storage items like chest, cabinet…etc. It is basically same system, but with one difference. Each storage object having its own inventory and with multiple storage objects in the game world, I need to make sure game will display inventory only of storage item player is interacting with. For this purpose I’m going to use simple collider, which defines interactable area of storage object, one more variable which defines which specific storage object player is interacting with, and also array “storageInventory” which holds all items in the storage.

Storage object consist of 2 meshes (top and bottom part) and one collider to detect if player can interact with chest. On interaction event, top part of the chest will open and chest inventory UI is displayed.
So basically I cast to player character, getting highlighted object variable, which is set by collider (onCollisionEnter / onCollisionExit). Next cast is to the storage item class, where highlighted object defines which specific storage object player is interacting with. From there I can extract required information, like inventory variable, storage size if I want to have more different types of storage objects with different capacity…etc. All these variables are then used to create storage inventory UI window.

So let’s test it now, everything should work (hopefully) and this episode can be closed.

So everything works (for now). Items can be picked, equipped/unequipped, player changes appearance based on equipped items, each storage chest has it’s own inventory and capacity…etc. That’s hopefully basic inventory/storage system done. But I will probably get back to it later (I’m sure I’ve forgot something that will come up later). Now just add some footnotes and that’s me done for now.

Footnotes

  • enemy inventory system – not going to implement inventory system for enemies. I will probably use simple array of objects that enemies can drop once killed. So I will need to add one more variable to item variables collection that defines chance of item being dropped by killed enemy (for each item in enemy inventory array, get “dropChance” variable, perform roll, if “dropChance” => random integer in range 0-100, spawn item)
  • Crafting system – have a look at crafting system. Thinking about few types of crafting tables (can possibly use itemType enum from item variables collection). Have look at recipes system also (could be learned? Unlocked by skill? Dropped by enemies? Need a specific NPC character to craft items, i.e. armorsmith, weaponsmith, alchemist…etc.?).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑