I'm making a horror game #05
From first person to third person, and how I swap held items.
I'M MAKING A HORROR GAME
In this 5th edition of I'm making a horror game, I'd like to briefly go over a small problem I encountered and how I solved it.
First and foremost, after careful consideration, I've decided to make the game an homage to the classic horror games I grew up with. This is referring to titles such as Resident Evil, Alone in the Dark, etc.
What does it mean? Well, I've shifted from a first person perspective to a third person perspective using fixed camera angles. My main concern with this change is the loss of immersion that a first person perspective offers.
But that's not the goal of today's post, no. Today I wanted to talk about a small issue I encountered this morning and the simple fix I applied to solve it.
The player has an inventory that can hold some items. When in the inventory, they can equip an item to spawn a copy of that item in the world, which is attached to a specific socket on the player's character.
The issue I was facing was that unequipping an item didn't exactly work. I would open the inventory, equip an item, unequip it, and somehow the game thought I was still holding it (despite the item being destroyed).
As you can see in the screenshot, whenever we swap held items, we compare the new item's inventory slot to the current held item's inventory slot. If they are the same, the player gets a message stating they are already holding this item, if they are different, then we proceed to swapping the items.
Therein lies the issue, if the "New Item" inventory slot is '0', then the "Held Item" (which is reset when unequipping) would always return true, as the default inventory slot is '0'.
So how did I solve it? Well, it was very simple.
As I said before, the solution to this is very simple.
All I had to do was set the default of the "Held Item" variable with an "Inventory Slot" of '-1'. This means that anytime an item is unequipped, the value that'll be compared when swapping to a new item will be '-1'.
The new default is a value that will never be possible in the "New item", so we are able to equip and unequip items as we see fit.
See? I told you it was super simple.
In the meantime, consider subscribing to the mailing list so you can get important updates, freebies, and a link to the demo as soon as it's available.
See you in part #06!