I am making a 3D tic tac toe, where a 3x3x3 cube holds blue and red placemarkers instead of Xs and Os. The lines can go up, down, straight, diagonal, etc. I have code that checks whether three placemarkers of the same color are in a row. Each block checks for blocks around itself. If they are the same color, a vector is made with these two blocks, creating a line. Then I use this line to raycast for another block to make a threesome. I have managed to get the script to recognize two in a row, but not three. I’m guessing it has to do with either the vectors or the casts. Here is my code(C#):
public bool checkRow(string t){
Collider[] col = Physics.OverlapSphere(transform.position, 0.9F);
foreach (Collider c in col){
if (c != collider && c.CompareTag (t)){ //check if neighbor and same color
Debug.Log ("Found neighbor");
Vector3 oneDir = c.transform.position - transform.position;
oneDir.Normalize();
Ray r = new Ray(c.transform.position, oneDir);
RaycastHit hit;
if (c.Raycast(r, out hit, 0.9F)){
Vector3 twoDir = hit.transform.position - transform.position;
twoDir.Normalize();
if (Vector3.Angle(oneDir, twoDir) < 5 && hit.transform.CompareTag(t)) //if the row is straight and the last one has the same color)
return true;
}
}
}
return false;
}
What could it be missing?