Unity version: 2019.4.11f1
Hi, I’m having an issue trying to detect dead-ends in my game board generation.
So far steps 1 to 6 work as intended, and yield a random board every time, comprised of tiles and paths generated at random, like so:
[173578-onpaste20210104-190525.png*_|173578]
Now what I’m trying to do with step 7b is: for each path that isn’t inactive, check if it’s a dead end.
The way I’m trying to go about this is: for each path that isn’t inactive, add a OverlapBox() at each extremity that counts the number of active game objects. If that number is one (meaning it found only the path it’s checking from), then it’s a dead end.
When I run that part of the script though, I get this:
[173579-onpaste20210104-190556.png*_|173579]
What I suspect is the problem (idk if it really is that) is that instead of creating the boxes A and B at +/- y relative to the game objects, it’s adding or subtracting y relative the the world. Again, it could be something else entirely, I’m really not sure.
Here’s the method called by step “7b - Remove Dead Ends”:
public void RemoveDeadEnds()
{
Debug.Log("RemoveDeadEnds() started");
// maybe I need to make everything active at the start (and then deactivate untagged at the end)?
// for each path that isn't untagged, get their hitCollisions
for (int i = 0; i < allPaths.Count; i++)
{
if (!allPaths*.gameObject.CompareTag("Untagged"))*
{
// this part is fucked, I don’t think it places the boxes at the correct position. I suspect it adds the new Vector3() +/- y relative to the world, instead of the gameobject
Collider hitCollidersA = Physics.OverlapBox(allPaths.gameObject.transform.position + new Vector3(0, allPaths_.gameObject.transform.lossyScale.y / 2, 0), new Vector3(0.4f, 0.4f, 0.8f)); // removed: allPaths*.gameObject.transform.localRotation*
Collider[] hitCollidersB = Physics.OverlapBox(allPaths.gameObject.transform.position + new Vector3(0, -allPaths.gameObject.transform.lossyScale.y / 2, 0), new Vector3(0.4f, 0.4f, 0.8f)); // removed: allPaths*.gameObject.transform.localRotation*_
if (hitCollidersA.Length == 1) //I don’t understand if it should be 1 or 2 help (en vrai ils ont pas l’air de se voir eux-même donc 1 paraît correct)
{
Debug.Log("RemoveDeadEnds() - " + allPaths*.gameObject.name + “: DEAD END (hitCollidersA)”);*
for (int n = 0; n < hitCollidersA.Length; n++)
{
Debug.Log(“hitCollidersA[” + n + "] = " + hitCollidersA[n].gameObject.name);
}
allPaths*.gameObject.tag = “DeadEnd”;*
allPaths*.gameObject.GetComponent().material.SetColor("Color", Color.yellow);*
}_
if (!allPaths*.gameObject.CompareTag(“DeadEnd”))*
{
if (hitCollidersB.Length == 1)
{
Debug.Log("RemoveDeadEnds() - " + allPaths*.gameObject.name + “: DEAD END (hitCollidersB)”);*
for (int n = 0; n < hitCollidersB.Length; n++)
{
Debug.Log(“hitCollidersB[” + n + "] = " + hitCollidersB[n].gameObject.name);
}
allPaths*.gameObject.tag = “DeadEnd”;*
allPaths*.gameObject.GetComponent().material.SetColor("Color", Color.yellow);*
}
}_
if (!allPaths*.gameObject.CompareTag(“DeadEnd”))*
{
Debug.Log("RemoveDeadEnds() - " + allPaths*.gameObject.name + “: skip”);*
}
// set newly deactivated path’s tag to “Untagged” and color white
}
}
}
----------
Thanks in advance for any help or input!
*
*