- Home /
Flattening terrain under my object at start()
I need to flatten the terrain of an object at the start when it is activated/instantiated into the scene. I want to use a specific box collider to do it.
So basically, how would I flatten the terrain within this collider?
Here is the script so far.
//Collider.
public Collider boundsCollider;
void Start () {
//Flatten ground around before starting the bitch up..
//Cast ray down to check and get terrain.
Vector3 dRayDir = transform.TransformDirection(new Vector3(0,-100,0));
Ray dRay = new Ray(transform.position, dRayDir);
RaycastHit dhit;
if(Physics.Raycast(dRay, out dhit, Mathf.Infinity)){
var terrain = dhit.transform.GetComponent<Terrain>();
}
//So what to do with the collider and how to access the tiles(points?) on the terrain within said collider?...
}
Help... thanks.
Answer by getyour411 · Dec 29, 2014 at 12:27 AM
This is not a simple thing. Search on 'Dynamic terrain deformation' for examples, and although those are usually written from the perspective of terrain changes from explosions or similar, the functions you will need potentially serve as examples (splatmap mgmt., heightmap mgmt. and the terrainData class).
A search on Dynamic terrain deformation turns up many links.
Your answer
![](https://koobas.hobune.stream/wayback/20220613175054im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I don't know why i can't detect by ray sth. tagged, 1 Answer
Creating a working meshcollider in code 3 Answers
Raycast isnt working 1 Answer
object reference not set to an instance of an object 1 Answer
Raycast problem trough the terrain 1 Answer