- Home /
why does Infinite Runner Terrain Collider break my game?
So I'm working on an infinite runner game in which the player stays still but the ground is constantly moving in his direction giving the feel of him running. heres the move script applied to the terrain
` using UnityEngine; using System.Collections;
public class MovementScript : MonoBehaviour { public float enviroSpeed = 10.0f; // how fast the player is moving public Vector3 moveDirection = Vector3.forward; // what direction the player is moving
// Update is called once per frame
void Update ()
{
transform.Translate(-moveDirection * enviroSpeed * Time.deltaTime);
}
}
there are 3 pieces on screen at a time once one moves behind the player it hits a collider that spawns another random prefab then destroys itself. right now i have 8 simple Prefabs that are made up of a colored ground box, a collider at the front that lets me know when its hit the destroyer box and then a spawn box that is the exact same size as the front collider box and exactly 3 ground cube lengths away from the front cube. my spawn script which is attached to my Prefabs is this using UnityEngine; using System.Collections;
public class DestroyScriptAlt : MonoBehaviour {
public Transform spawnPoint; // spot object will spawn new terrain at. Exactly 3 places away
public GameObject[] obj;
void OnTriggerEnter(Collider other)
{
if (collider.tag =="base" )
{
Instantiate (obj[Random.Range(0,obj.GetLength(0))], spawnPoint.position,Quaternion.identity);
Destroy(this.gameObject);
}
}
}
This all works just fine up until i add a forth piece to the Prefabs. in Maya i made interlocking terrain pieces that whose verts always start and end at exactly the same spot. so that no matter what combination of random pieces it gives me they will always fit. this too works until i add the much needed colliders on these meshes. then it all goes crazy.
i get lots of mesh overlay it spawns more objects than needed i thought it might be detecting all objects entering the collider thats why i added that if tag == base part . it sometimes take a while for this to happen. but i have noticed the higher the terrain movement speed is set the fast it happens...any help on what I'm doing wrong would be greatly appreciated.