How to deform a mesh on placing gameobject?

Hi everybody,

I’m currently working on a gaming which uses a low poly procedural terrain which will be generated at runtime. See this as a large subdivided plane. I created this by following the terrain generation tutorials of Brackeys. This works as intended and now I want it to deform when a game object (a model of a building) has been placed on it. How can I do this?

I currently spawn the building using the position of a raycast and then instantiating it there but it just clips through the terrain mesh. How can I make it so that the clipping parts (that are in the building collider?) flat out when it is instantiated?

Ohh and does anyone know a good tutorial about mesh deformation in general without the mesh bouncing back to it’s original shape?

Thanks upfront,

Hi mate, I’m not sure if this would work but you could try doing the following:

  1. Get the position of the raycast hitpoint
  2. Calculate the vertices that need to be changed (according to how big the width and breadth of the building you want to spawn is)
  3. Get the average height value of the affected vertices
  4. Set all vertices to this new average height
  5. Spawn the building at a position of the average vertices height + 1/2 the building’s height (so it’s centered)

Hope this helped =)