I posted a question in Unity answers about 2 days ago and was awaiting moderation when suddenly it stated that it was rejected. I tried to create an honest question and with as much detail as possible in hopes to not make it vague.
here is a link to the question: http://answers.unity3d.com/questions/852315/platform-generation.html
In case the link is no longer available here is a copy of the question I posted:
I am trying to create a similar effect to Bastions ground generation:
I have come close to creating the effect I want however I am trying to find a more efficient way of doing it. So far I have a plane with no mesh rendered to act as a ground for the player. It is surrounded by several triggers that instantiate a cube below them and change its y position as well as z scale to emulate the ground being constructed where the player moves.
Image of Unity Project: http://i.imgur.com/B8lx4OS.jpg
Does anyone know of a way to create more efficient code in terms of using lets say one giant trigger in which cubes spawn below the player depending on its position. Any other way of creating this effect would be helpful. Thanks again for the help.
code for trigger:
```csharp
**using UnityEngine;
using System.Collections;
public class boundary : MonoBehaviour {
public GameObject ground;
public Material newMaterial;
private bool playerInTrigger;
private float transformSmooth = 10f;
private float colorSmooth = 5;
private float xPos;
private float yPos;
private float zPos;
private float xScale;
private float yScale;
private float zScale;
private Vector3 originPos;
private Vector3 newPos;
private Vector3 originScale;
private Vector3 newScale;
private GameObject groundClone;
void Awake ()
{
playerInTrigger = false;
groundClone = Instantiate (ground, new Vector3 (transform.position.x, transform.position.y -3f, transform.position.z),
transform.rotation) as GameObject;
xPos = groundClone.transform.position.x;
yPos = groundClone.transform.position.y;
zPos = groundClone.transform.position.z;
xScale = groundClone.transform.localScale.x;
yScale = groundClone.transform.localScale.y;
zScale = groundClone.transform.localScale.z;
originPos = new Vector3 (xPos, yPos, zPos);
newPos = new Vector3 (xPos, yPos + 1.5f, zPos);
originScale = new Vector3 (xScale, yScale, zScale);
newScale = new Vector3(xScale, yScale + 2, zScale);
}
void FixedUpdate ()
{
if (playerInTrigger == true)
{
groundClone.transform.position = Vector3.Lerp (groundClone.transform.position, newPos, transformSmooth * Time.deltaTime);
groundClone.transform.localScale = Vector3.Lerp (groundClone.transform.localScale, newScale, transformSmooth * Time.deltaTime);
groundClone.renderer.material.color = Color.Lerp (groundClone.renderer.material.color, newMaterial.color, colorSmooth * Time.deltaTime);
}
else if (playerInTrigger == false)
{
groundClone.transform.position = Vector3.Lerp (groundClone.transform.position, originPos, transformSmooth * Time.deltaTime);
groundClone.transform.localScale = Vector3.Lerp (groundClone.transform.localScale, originScale, transformSmooth * Time.deltaTime);
}
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.name == "Player")
{
playerInTrigger = true;
}
}
void OnTriggerExit (Collider other)
{
if (other.gameObject.name == "Player")
{
playerInTrigger = false;
}
}
}**
```