Posted May 25, 2024 by Argendel
#inventory #inventory system #personal inventory
To make the inventory system truly useful, it's essential to move items between different inventories. When you drag and drop an item, a graphic raycast is triggered to detect where the mouse is. If the item intersects with an InventoryView
component (responsible for drawing the inventory), bingo! If not, the item is removed from the inventory (for now). In the future, you'll be able to place these items directly into the world.
If you move an item to a different inventory, first it gets removed from the original inventory and added to the new one, assigning new viewport coordinates to ensure it appears in its new location.
Moving items between blocks can be confusing, so I added a LineRenderer
that visually connects the inventory to its corresponding block, helping you avoid losing reference.
One of the most requested features: weight. Each inventory has a maximum weight and an overflow weight. For example, if a backpack has a maximum weight of 20kg and an overflow of 2kg, your character will move slower if they exceed 20kg but won't be able to carry more than 22kg. This adds a layer of realism and strategy to the game.
To better manage these parameters, I created the InventorySettings
class, which contains the inventory IDs, maximum and overflow weights, and which prefab will be used. This allows even items to have their own inventories if needed.
As a player with certain OCD tendencies (myself included π ), I know that moving items βby eyeβ is frustrating. So I added a "snap" function that activates when you press the "alt" key. Items move to fixed positions and can be rotated with the mouse scroll, allowing for perfect order!
For those adrenaline-filled moments when you need to loot quickly, items will be placed randomly in your inventory. Yes, it can be messy, but it reflects the chaos of those extreme situations. You can organize everything later when you have more time.
Pressing the 'TAB' key will open your personal inventory, configurable for different types of inventories throughout the game. The subID of this inventory is a configurable string, allowing you to switch inventories easily.
The inventory consists of 5 spaces:
This design ensures you always have your tools and weapons within reach. πͺ
For next week, I plan to work on the following features:
Thanks for reading! I hope to hear your comments and suggestions to keep improving. See you next week! π