// Generate walls based on the parameters of the previous enclosure // TODO: Make 2d trials work with their own enclosures. private void Generate2dWalls() { var previousTrial = E.Get().CurrTrial.TrialProgress.PreviousTrial; //This computes the current interior angle of the given side. var interiorAngle = 360f / previousTrial.enclosure.Sides; //This is, of course, given as 360 / num sides //This sets the initial angle to the one given in the preset float currentAngle = 0; //Here we interate through all the sides for (var i = 0; i < previousTrial.enclosure.Sides; i++) { //We compute the sin and cos of the current angle (essentially plotting points on a circle var x = GenerateWall.Cos(currentAngle) * previousTrial.enclosure.Radius + previousTrial.enclosure.Position[0]; var y = GenerateWall.Sin(currentAngle) * previousTrial.enclosure.Radius + previousTrial.enclosure.Position[1]; //This is theoreticially the perfect length of the wall. However, this causes a multitude of problems //Such as: //Gaps appearing in large wall numbers //Desealing some stuff. so, bad. var length = 2 * previousTrial.enclosure.Radius * GenerateWall.Tan(180f / previousTrial.enclosure.Sides); //Here we create the wall var obj = Instantiate(Wall, new Vector3(x, 0.001F, y), Quaternion.identity ); //So we add 10 because the end user won't be able to notice it anyways obj.transform.localScale = new Vector3(length, 4F, 0.5f); //This rotates the walls by the current angle + 90 obj.transform.Rotate(Quaternion.Euler(0, -currentAngle - 90, 0).eulerAngles); //And we add the wall to the created list as to remove it later _created.Add(obj); //And of course we increment the interior angle. currentAngle += interiorAngle; } }