Survival Game Development using Godot
Working on a crafting bench
14th January 2025
Before the player can create the bench, the amount of sticks the player has will need to be checked. Using the check amount function (below), I have used a for loop to go through each slot in the inventory and check where the stick is located, then retrieve the item amount. Then I have used a simple if statement to check the amount of sticks and a bool to check if the correct button has been pressed.
If the player has the correct amount, the bench will be created by calling the create bench function in the player script and also deduct from the item amount to ensure it can’t be created repeatedly.
Using the default crafting area, the player will be allowed to craft a bench using 6 sticks.
The code to create the bench is a simple use of ‘instantiate’ to a position in front of the player. By storing the player’s global transform and adding and multiplying the direction they are facing by 1, for example in this snippet, it will create the bench in front of the player.
This will work by adding the newly created bench as a child to the scene.
There are however issues that I need to fix. The player can craft items on top of one another, so I need a way to check if the space in front of them is clear to place. Potentially using the ray cast to detect if something is already there.