Hey! I’m making a game with procedurally generating roads. its all working pretty well, but I have to get them to stop overlapping one another.
to do this I’ve put a trigger with a rigidbody(no gravity, is kinematic) on each road section. the idea is that if the triggers touch, they’ll activate ontriggerenter and I can then have the program fix the overlap. However, ontriggerenter only fires some of the time.
I’m also getting a weird “object reference not set to an instance of an object” error over and over. I’ve checked the line in question and I think everything should be working. I’ve prepared some images to show you the problem in more detail. does anyone know what the problem could be? Thanks for your help!
[38476-use+triggers+to+detect+overlaps.jpg|38476]
[38477-mysterious+error±+very+related.jpg|38477]
And here’s the code in question:
using UnityEngine;
using System.Collections;
public class RoadStartstuff : MonoBehaviour
{
GameObject Director;
GameObject parent;
public int degreeturn;
public int degreessofar =0;
public GameObject beforeme;
// Use this for initialization
void Start ()
{
Director = GameObject.Find ("Director");
parent = this.transform.parent.gameObject; //this gets the parent of this road start so we can filter out self collisions later...
}
// Update is called once per frame
void Update ()
{
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.transform.parent.gameObject == parent)
{
//do nothing, you're colliding with yourself idiot.
Debug.Log ("self collision. ignore.");
}//end if
else
{
//Debug.Log(Director.GetComponent<Director>().OMGoverlap);
Director.GetComponent<Director>().OMGoverlap = true; //<-----this is line 38 in monodevelop
Debug.Log ("OMG WE HAVE AN OVERLAP BRUH! " + other.gameObject.transform.parent.gameObject.name);
//here we also want to remember which type of road section was used when we collided so we can check later if all road sections have been tried.
//we'll use a new array in the director that matches the protoroadsection array to keep track
//once all possible road sections are tried, just cap it with a really slim special cap secion.
}//end else
}
}