Monday, September 5, 2016

Sandbox Coding Progress

  Inventory systems and sandbox features are some pretty beefy feats of coding found in modern games. Though they seem like relatively basic features, actually generating executable code that will preform the way you'd like it to is rather challenging. There are many things that can go wrong and there are some trivial problems you can run into. The logistics of everything is pretty easy to solve, but again, making the code is what's difficult.

  So, let's basically outline what we wanted to make for this update.

  The player can walk around in the world. While walking around in the world, players will be able to pick up certain objects; specifically, actors that have a special flag associated with them; "canPickUp". If the item we come across can be picked up, then the player can press F to pick up the item. When the item is picked up, it is removed from the world, and the weight of the item is added to a variable called "currentlyCarrying." (This actually happens before the object is picked up so we can see if the player can carry it, as "currentlyCarrying" is compared to "maximumCarryingWeight", but anyway...) When the actor is picked up from the world, it is added to the player's inventory. Nothing too complex, right?

An object that can be picked up in the world. This is our debug item.

  Let's move on to the sandbox aspect. When sandbox build mode is entered, the player will run a ray trace from their camera, over to what they're looking at. Whatever we want to build will be placed at the impact point of that ray trace. If the object can be built there, the object will have a green glow to it. If it can't be placed there, then the object will have a red glow. (I'm not going to get into the complex ideas behind checking the ground angle the build object is being placed on, or in checking proximity to other objects.)


  The object can then be placed in the world with a white "ghost texture." This is our blueprint of what we want to make. The idea is that the player leaves to collect the supplies needed to build this object. Until they have the supplies, they'll be able to walk through the blueprint. When they come back, if they have the required supplies, they can press F to build the item. The objects and object weights are removed from the inventory, and the item is built in the world. A little heavy, but simple, right?


  I'm not going to cover all of the details of the inventory system since it's something that has been done for a few update cycles, but I'd like to go over a problem I was having with removing the items from the player's inventory when they try to build something.

  One would assume the solution to this problem is to simply look through the player's inventory and if they have the item that is needed to build their blueprint, then remove an item of that type n times until the times that item type was removed matches what was needed for the building. After that, we add up the weights of the objects needed, and subtract that from what we're currently carrying in our inventory.

  Logically, that's exactly what is happening. However, the solution isn't as cut and dry as the plan. Below is a video explaining the issues that were encountered and why the plan isn't able to be coded into the game as it is.


  In addition to being able to place a debug item in the world and building it, I've also created a feature that allows the player to open an interface and choose what they want to build, as outlined below.


  Above are two screenshots that show the player being able to open the survival book, as well as being able to turn it's pages. Every page is associated with an actor that is able to be built in the world. In the final version of the book, there will be informative pages scattered between pages that allow the player to build different objects. These pages, as shown with the inside cover and title page, will not have an interface to "plan" building an object.

  It's also in the development path that there will be sections of the book the player can turn to to avoid thumbing through a bunch of information they don't need, over, and over. The book will save the page you were turned to, so the player can open to it again if they need to build multiple items of the same type; they don't need to find it every time. We also plan on having a feature where players can "dog ear" pages. This will be the equivalent of "favoriting" a page to reference back to it later.

Multiple planning blueprints being added to the game by use of the survival handbook interface.

  We soon hope to have a video detailing all of these features that will be used as a Patreon content update.

No comments:

Post a Comment