I’m trying to spawn invisible walls around my screen dynamically through script and so far I’ve managed to find the bottomLeft, topLeft, topRight & bottomRight Vector3 coordinates.
I wrote this method to create a wall but the orientation of the wall seems to be off:
void SpawnWall(string wallName, Vector3 startPosition, Vector3 endPosition, Vector3 center)
{
// Create & center the wall between the start and end positions
GameObject wall = new GameObject(wallName);
wall.transform.position = (startPosition + endPosition) / 2;
BoxCollider wallCollider = wall.AddComponent<BoxCollider>();
// Adjust the collider size and position
wallCollider.size = new Vector3((endPosition - startPosition).magnitude, wallHeight, wallThickness);
// Make the wall face towards the center
//Vector3 direction = Vector3.Cross(startPosition, endPosition);
wall.transform.LookAt(center);
walls.Add(wall);
}
The red, blue, green & pink lines on the screen are the boundaries I’m trying to create the invisible walls. These are the positions I’m testing with:
Vector3 bottomLeft = new Vector3(-13.80, 0.00, -6.82);
Vector3 topLeft = new Vector3(-17.52, 0.00, 13.02);
Vector3 topRight = new Vector3(14.43, 0.00, 9.41);
Vector3 bottomRight = new Vector3(6.38, 0.00, -9.10);
I would appreciate any tips or advice on this matter. Thanks!
