Trench Building in Unity — Dev Log

What does a trench look like?

The finished trench looks like this;

End Product
  1. Dig Trench — Alter the Unity Terrain based on a user defined set of points and dimensions
  2. Add ‘Revetment’ — add paneling on the inside of the trench
  3. Add Back-fill — add a material to fill between the revetment and the terrain.

Digging a Trench

I created a Custom Editor that visualizes where the trench will go. It consists of several features;

Adding Revetment

Once the trench has being dug, the next step is typically to add the revetment. I confess that I have not created a algorithm to the collisions, so initially it is just approximately where the user needs it. I.e. they still have to make the final adjustments.

Before User Adjustments
After User Adjustment

Adding Back-fill

That last stage is fill the gaps between the revetment and terrain. This is needed because typically the resolution of the terrain is not finely grained enough to make small adjustments. This means the trench is created wider than specified to ensure required trench width is met. Therefore we need to back-fill the gaps with a couple of game objects per straight trench-run. The auto-generated back-fill again requires User interaction.

Before User Adjustments
After User Adjustments

Where now?

There is still *a lot* of improvements I could make to the editor. I have the majority of the dimensions to mitigate the number of user adjustments required, but currently for my project, the cost-saving ratio does not warrant it. But if I were to make this a Run-Time feature then it would be a different story.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Paul Marsh

Paul Marsh

Unity, VR, Enterprise and .Net Developer