- Home /
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,
Answer by jimmycrazyskills · Dec 22, 2018 at 04:59 PM
Hi mate, I'm not sure if this would work but you could try doing the following:
Get the position of the raycast hitpoint
Calculate the vertices that need to be changed (according to how big the width and breadth of the building you want to spawn is)
Get the average height value of the affected vertices
Set all vertices to this new average height
Spawn the building at a position of the average vertices height + 1/2 the building's height (so it's centered)
Hope this helped =)
Your answer
![](https://koobas.hobune.stream/wayback/20220612183204im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Procedural Generation 0 Answers
Writing a Custom Collider 0 Answers
Breaking down Unity's Procedural Example "sculpt vertices" 1 Answer
creating a mesh procedurally 4 Answers