- Home /
Overlapping Prefabs
i have a permanent terrain rendering set up, it randomizes the hills and stuff aswell but when the next "chunk" shall we say is rendered it will be fine until you walk to a new "chunk", at which point it will spawn a new "chunk" were a previous one would be, i have tried a few different ways to delete the newly rendered chunk if it overlaps an exsisting one.
#pragma strict
var terrainpplane:Transform;
private var colliderr:boolean = false;
var spawn:boolean = false;
var boom:boolean = false;
function Update () {
var boxCollider = gameObject.GetComponent(BoxCollider);
if (colliderr == false)
do{
boxCollider.size = Vector3(500, 30, 500);
boxCollider.isTrigger = true;
colliderr = true;
}while(colliderr == false);}
function OnTriggerEnter (other:Collider)
{
if (other.CompareTag ("Plane"))
Destroy (gameObject);
if (other.CompareTag ("Player"))
{
if (boom == false){
do{
yield(WaitForSeconds(5));
var instancesnow1 = Instantiate(terrainpplane, Vector3(transform.position.x + 500, 0, transform.position.z), Quaternion.identity);
var instancesnow2 = Instantiate(terrainpplane, Vector3(transform.position.x - 500, 0, transform.position.z), Quaternion.identity);
var instancesnow3 = Instantiate(terrainpplane, Vector3(transform.position.x , 0, transform.position.z + 500), Quaternion.identity);
var instancesnow4 = Instantiate(terrainpplane, Vector3(transform.position.x , 0, transform.position.z - 500), Quaternion.identity);
spawn = true;
boom = true;
Destroy (this);
}while (!other.CompareTag ("Player"));}}}
NOTE i have tried using sphere collider but it doesnt work and instead deletes itself even when it's not touching anything and it is the only thing in the scene -- It spawns plane prefabs which randomly changed with other scripts -- "snowprefab" is from a previous game i made, i will change it later
This doesn't really answer your question but it might be relevant. I'm not exactly sure what you are trying to do but my assumption is you want a infinite terrain. Why reinvent the wheel?
http://forum.unity3d.com/threads/68807-Infinite-Terrain-Free-Project-Source
http://upshift.org/2012/02/building-endless-terrain-in-unity3d/
Ignoring these you should look into using Terrain.SetNeighbors to seamlessly place a terrain grid.
I like the idea of a few of them, but i want to make the map render similar to "cubeworld" were it renders the surrounding 4 planes except the ones that already have loaded. i like the Terrain engine and think it would be perfect for what i want but i cant spend £3000 on something that isnt even the main aspect of my game, i would like it simpler and free if possible.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112019im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Respawn random objects 1 Answer
Collision detection problems with plane + 2D Sprites 0 Answers
Assign particle collision in code? 0 Answers
Multiple collision areas within plane 0 Answers