1. Dungeons & Kingdoms
  2. News

Dungeons & Kingdoms News

Developer's Blog - Behind the scenes with Rock Formations

[p]This post is for anyone interested in what goes on from a developer's perspective.[/p][p][/p][p]In this post I'm going through some of the steps involved taking a single rock model and processing it into a fragmented and harvestable resource the player can smash or cut to generate a variety of smaller resources. I wanted to share some of the behind-the-scenes work that goes into game mechanics like this.[/p][p][/p][p]There are multiple ways this could be done, but my main goal was to create my own editor tools and processes to be able to easily repeat this on several different rock models, as well as be able to re-run the process if I need to make adjustments (different fragment shapes/sizes, different resource spawn points etc). My preference is to stay within the Unity editor when possible.[/p][p][/p][p]What I start with - any one of a variety of rock shapes and sizes. These are single mesh models. The only difference the model makes is how long it takes the automated processes to run, otherwise all steps are the same.[/p][p][/p][p][/p][p]What I end up with - a rock formation players can smash into smaller resources, which can then be broken up into even smaller resources.[/p][p][/p][p][/p][p][/p][h3]Fragment the model into shards[/h3][p]I'm using Rayfire for the fragmentation and connectivity features. While Rayfire has built-in fragmentation patterns for square and random shapes, I needed more control than what it offers so I use a custom point cloud with my own custom settings. The point cloud is generated from a starting point that covers a number of rows and columns with variable randomized spacing.[/p][p][/p][p]Square fragments are for mining stone blocks from a quarry. That is for advanced stonemason jobs where they have the knowledge and tools to cut square blocks from stone.[/p][p][/p][p][/p][p][/p][p]The starter unskilled job is Stonebreaker. For that I need randomized shapes as the tools and skills don't allow for precision stone cutting, only rock smashing into smaller pieces.[/p][p]Both fragment patterns also allow the player to cut rooms or tunnels out of rock formations creating cozy caves and protected areas.[/p][p][/p][p][/p][p][/p][h3]Fragment Each Shard Into Smaller Pieces[/h3][p]Each rock shard created by the previous point cloud also needs to be fragmented so I can control things like the visual effect of showing cracks when a shard is hit, and creating a nice explosion effect when a shard is demolished revealing new resources inside.[/p][p]I wrote routines to iterate over each shard, add my own custom components and automate fragmenting them with Rayfire into standard voronoi patterns.[/p][p][/p][p][/p][h3]Saving Generated Mesh[/h3][p]Smaller rock formations end up with 10-20 shards, larger formations end up with over 400.[/p][p]Each of those shards are then fragmented into 20-40 pieces each. That's thousands of new mesh files, but they only exist inside the scene view in the editor.[/p][p]I wrote custom routines that export the mesh data into asset files on disk. There are tools to do it manually for each rock shard, but I don't want to sit there clicking buttons and finding folders for thousands of shards. Now, it's one button press.[/p][p][/p][p][/p][h3]Generating Resource Spawn Points[/h3][p]Each rock shard will reveal a variety of potential new resources when it is demolished. These new resources spawn at specific points within the demolished shard.[/p][p]I setup my first rock formation by manually placing where the spawns should go. Seeing how time consuming and tedious that was, I then wrote new routines to fully automate the processes.[/p][p]Now, all I need to do is add the prefabs for the resources I want to spawn into a list and click a single button... and wait :)[/p][p]Larger rock formations with 100's of shards can take 5-10 hours to processes. I could optimize this further but it will probably always be an overnight job.[/p][p][/p][p]The automated process...[/p][p]A point cloud is generated that covers the entire shard based on its bounding box and my custom settings for things like spawn point spacing/density.[/p][p][/p][p][/p][p]Each potential spawn point is then tested by raycasting on all axis towards a small generated collider at each cloud point position. If all raycasts don't hit the collider, it is tracked as a valid potential spawn point for prefabs.[/p][p][/p][p][/p][p]Each type of spawn prefab is then instantiated and positioned at each valid potential spawn position. I use what I call boxcasting to confirm the spawn is entirely inside the mesh shard. Raycast origin points are generated for each axis (x, y, z) offset on both positive and negative. This creates a 6 sided cube of raycast origin points that all target the instantiated spawn object. If any raycasts hit the prefab object then it fails at that position. This works for both convex and non-convex shards.[/p][p]Each spawn prefab that fits inside is then tracked and checked for bounds intersection with other tracked prefabs. Overlaps are discarded.[/p][p][/p][p]This shows what boxcasting looks like. There is a small stone prefab partially inside the shard. Raycasts are made from each point shown, but only failed raycasts show a red line. I would normally end the test on the first failed raycast but I let it run to demonstrate the full box.[/p][p][/p][p][/p][p]This shows each valid point cloud position being tested for each spawn prefab type.[/p][p][/p][p][/p][h3]The Result[/h3][p]I end up with a highly configurable and easily repeatable process to create or tweak rock formations to allow for player destruction that can spawn new resources for harvesting.[/p][p]This effort also leads up to other game mechanics coming during early access such as building destruction and allowing for the player to clear collapsed tunnels and break through walls on adventures, if they have the right tools and skills of course.[/p][p][/p][previewyoutube][/previewyoutube][p][/p][h3]Feedback[/h3][p]I'm not sure how many of these developer-focused blogs I'll make. Let me know in the comments if these types of posts interest you.[/p][p][/p]

New Build 0.587 - New Builder Pieces, Resources, and Bug Fixes

[h2]New full game build 0.587[/h2][p][/p][h2]Highlights[/h2]
  • [p]New harvestable resource - Wild Einkorn[/p]
  • [p]Both harvestable water reeds and einkorn can be harvested for a new resource, straw[/p]
  • [p]Straw can be used to make a new resource, thatch bundles for building, and other items like straw beds which improve health recovery and provide increased comfort[/p]
  • [p]Harvested vegetation is now saved and loaded correctly[/p]
  • [p]Several harvestable resources have been hand painted to provide more items at the starting location as well as more natural looking distribution such as wild fields in the plains of the map[/p]
  • [p]11 new build pieces configured for sandbox including interior stairs! Now you can build multi-story buildings.[/p]
[p][/p][h2]Release Notes[/h2]
  • [p]Rework how the vegetation and harvesting systems deal with instancing objects for both the player and workers. The goals is a more consistent and seamless interaction for both, and for the player to not be able to tell what is instanced and what isn't. This is necessary as new harvestable items are introduced as this enables more natural distribution of resources such as clusters of mushrooms in forested areas, and vast dense open fields of wild einkorn etc.[/p]
  • [p]Remove staged resources on builder map and replace with only instanced resources, minor performance improvement.[/p]
  • [p]Add player dialogue bark if they attempt an unknown action[/p]
  • [p]Add straw/thatch harvesting jobs and handcrafting options[/p]
  • [p]Move all harvestable resources to object pool management for better performance[/p]
  • [p]Remove Reed from default Gatherer workplace[/p]
  • [p]Remove isDefault field from assigned workplace product (also removed from savedata) as default products are now refreshed based on the original workplace definition[/p]
  • [p]Fix product controls not working for Gatherer workplace, you can now pause individual resources[/p]
  • [p]Add various controls for rigidbodies to help reduce the fly away effect on collision[/p]
  • [p]Reduce harvester max target distance[/p]
  • [p]Adjust harvester stop distance for some products[/p]
  • [p]Fix harvester not respecting production ratios[/p]
  • [p]Fix harvester not respecting distance limits[/p]
  • [p]Add spawn position offsets to harvest manager spawns to reduce ground collision intersection[/p]
  • [p]Enable save and load of vegetation data, fixes all vegetation/resources always respawning on load game[/p]
  • [p]Add new bark when worker can't find something to harvest that is valid production, eg. no reeds in range[/p]
  • [p]Increase max workers to 2 on build piece dirt floor (1201)[/p]
  • [p]Fix unhandled movesets ending up in unarmed fighting stance[/p]
  • [p]Remove old news entries from main menu[/p]
  • [p]9 new build pieces that use straw, 2 new build pieces for interior stairs so you can - now build multiple stories[/p]
  • [p]Fix typo in hints "Some UI will show the cursor…"[/p]
  • [p]Fix error where workers could stall trying to find a comfort source when all sources were reserved[/p]
  • [p]Hide pending build pieces counter text and hint panel when hiding all UI[/p]
[p][/p][h2]Known Issues[/h2]
  • [p]Some build pieces don't show construction progression correctly. Note they can still be completed correctly.[/p]
  • [p]NPCs don't position correctly for some comfort sources, eg. they don't stay in the correct position when sleeping in a bed[/p]
[p][/p]

New public_beta build 0.585 - New Content and Bug Fixes

[h2]New build on the public_beta branch[/h2][h3]
Highlights[/h3]
  • [p]New harvestable resource - Wild Einkorn[/p]
  • [p]Both harvestable water reeds and einkorn can be harvested for a new resource, straw[/p]
  • [p]Straw can be used to make a new resource, thatch bundles for building, and other items like straw beds which improve health recovery and provide increased comfort[/p]
  • [p]Harvested vegetation is now saved and loaded correctly[/p]
  • [p]Several harvestable resources have been hand painted to provide more items at the starting location as well as more natural looking distribution such as wild fields in the plains of the map[/p]
[h3]Release Notes[/h3]
  • [p]Rework how the vegetation and harvesting systems deal with instancing objects for both the player and workers. The goals is a more consistent and seamless interaction for both, and for the player to not be able to tell what is instanced and what isn't. This is necessary as new harvestable items are introduced as this enables more natural distribution of resources such as clusters of mushrooms in forested areas, and vast dense open fields of wild einkorn etc.[/p]
  • [p]Remove staged resources on builder map and replace with only instanced resources, minor performance improvement.[/p]
  • [p]Add player dialogue bark if they attempt an unknown action[/p]
  • [p]Add straw/thatch harvesting jobs and handcrafting options[/p]
  • [p]Move all harvestable resources to object pool management for better performance[/p]
  • [p]Remove Reed from default Gatherer workplace[/p]
  • [p]Remove isDefault field from assigned workplace product (also removed from savedata) as default products are now refreshed based on the original workplace definition[/p]
  • [p]Fix product controls not working for Gatherer workplace, you can now pause individual resources[/p]
  • [p]Add various controls for rigidbodies to help reduce the fly away effect on collision[/p]
  • [p]Reduce harvester max target distance[/p]
  • [p]Adjust harvester stop distance for some products[/p]
  • [p]Fix harvester not respecting production ratios[/p]
  • [p]Fix harvester not respecting distance limits[/p]
  • [p]Add spawn position offsets to harvest manager spawns to reduce ground collision intersection[/p]
  • [p]Enable save and load of vegetation data, fixes all vegetation/resources always respawning on load game[/p]
  • [p]Add new bark when worker can't find something to harvest that is valid production, eg. no reeds in range[/p]
  • [p]Increase max workers to 2 on build piece dirt floor (1201)[/p]
  • [p]Fix unhandled movesets ending up in unarmed fighting stance[/p]
[p][/p][h2]How to Access the public_beta build on Steam[/h2][p]See the official instructions from Steam https://partner.steamgames.com/doc/store/application/branches[/p][p]
Summary[/p]
  • [p]Find the game in your library[/p]
  • [p]Right click and select Properties[/p]
  • [p]Select Betas from the list on the left (under Installed Files)[/p]
  • [p]Select public_beta from the dropdown for Beta Participation[/p]
  • [p]Steam will now download the public_beta version of the game[/p]
[p][/p][p]The public_beta will be kept up to date as new builds come out so you don't have to switch back to the default full game version. Just note that builds under public_beta may contain other bugs and issues not found in the full game.[/p][p][/p][p]The public_beta branch is used to test and preview upcoming changes so we can get bug reports and feedback before updating the full game version.[/p]

HOTFIX for both Full Game and DEMO plus Store Page Changes

[h2]NEW HOTFIX![/h2][p]New builds out fixing the broken blueprint step of the tutorial.[/p][p]Full Game - v0.583[/p][p]DEMO - v0.584[/p][p][/p][h2]Store Page Changes[/h2][p]All media on the store page has been updated to better reflect what you can expect from the current sandbox mode gameplay.[/p][p][/p][p][/p]

HOTFIX! Fixes tutorial blueprint issue

  • Fix starter blueprint issues in tutorial
  • Fix Skills UI close button not working
  • Fix SKills UI not opening correctly the first time
  • Fix some starter resources on main gameplay map not initializing correctly