1

I am new to Unity and would like to be able to emulate the idea of 'digging' a hole in the 'earth' with a spade, at runtime and have the terrain slightly ahead of my camera lower slightly, then move that dug 'earth' into a pile somewhere next to the hole.

I have created a terrain using the preview terrain tools and now want to alter it at runtime a little like you see in this part of this video : https://youtu.be/l_2uGpjBMl4?t=2970

I want to be able to make a small 'dig' into my environment, just like a spade making a hole in the earth, and that state to then be something I can persist.

I then want to be able to move the 'dig' volume, i.e the 'earth' onto somewhere else in the terrain - literally imagine what happens when you dig a hole.

If I want to follow this guy's video, he is generating his terrain, and I am not sure how to apply his logic, because I would likely want to shoot a raycast from my camera, and where it intersects with the world, then alter the 'mesh' of my painted terrain, and then add to a 'pile' of earth somewhere else. I am not sure about just doing the piles of earth with just changing the height of the terrain, because there would need to be a volume associated with the 'earth' you have dug, so it's more of a object, than a terrain if you see what I mean.

I realise this is a bit of a braindump, but I am looking for direction and have done research these are the questions I would like answered, I want this to be a sounding board for whether my thoughts are on the right path, and if not, what is an optimal course for learning some techniques for achieving this.

halfer
  • 19,824
  • 17
  • 99
  • 186
RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130

1 Answers1

1

You need to use Terrain.terrainData which contains the GetHeights and SetHeightsDelayLOD methods. SetHeights is also available, but is not as efficient. Check the documentation to see how they work!

Marcos Pereira
  • 1,169
  • 14
  • 23