This is the first of many updates on Twig progress. Instead of regularly scheduled updates, I’ll be writing posts as features get implemented. Today’s post is about the grid placement system!
Those who joined my dev streams for the past week know what I’m talking about, but for the rest… As part of the game, the player will be able to build/repair/destroy furniture and also upgrade the inn. Instead of having premade inn layouts, there will be sections of floor governed by a grid placement system where furniture can be arbitrarily placed. Maybe a picture would explain this better?
Please, tell me how it works!
Update: This isn’t strictly correct anymore, see this post!
The base idea is that a grid will be placed on a defined rectangular area. Once a player switches to a placement/crafting mode the grid will become visible. When the player selects a prop then a ghost preview will appear. This preview will also indicate whether or not a specific placement is valid.
The rectangular grid area. Grid size (the grid is
Y squares) and unit size (each square is
unit) are defined in the editor.
- Inactive - Default mode, the grid is invisible.
- Selecting - Grid is visible, but there is no ghost preview.
- Placing - Ghost preview is visible and a prop can be spawned at any time.
When placing, the ghost mesh will snap to the grid in front of the player (as determined by the camera). Close enough to easily move to a specific location, but far enough away that the spawned object cannot collide with the player. Additionally, 90 degree rotations are allowed.
The ghost preview. Shaded transparent red or green to indicate if it’s OK to place. This can be given an arbitrary mesh so previews can look like the final placed object.
An interface for all objects that can be placed on the grid. Defines the object’s rectangular grid size and the mesh to use for ghost preview.
But how can it be extended?
What good is a placeable grid that can only spawn one item? Never fear, because
Enable Place Mode can spawn any class that implements
BPI_Placeable! This means that when I get the crafting/inventory system running I can just tie the two together. Once an item is selected in the crafting menu, the grid can be notified that it has a class ready to place.
Bonus fun points
As a last minute addition,
BPI_Placeable also exposes some variation parameters for each object. When an item is placed it will have a (typically small) random rotation and offset applied so repeated placements won’t be too uniform!
Want to see how the sausage is made? Tune in to (daily!) dev streams on Twitch.