It is highly possible that has been answered already, I’m terrible at vector math…

So what I am trying to do is have the user drag a wall for placement, I want to generate the mesh. So I have the starting and ending points as vector3s. Let’s say the wall has a width of 1. and the starting point happened to be (0, 0, 0) and the ending point was (0, 0, 5). I want to get the vertices:

- (0.5f, 0, 0)
- (-0.5f, 0, 0)
- (0.5f, 0, 5)
- (-0.5f, 0, 5)

So this will create a rectangle and then it is easy to extrude these points for the wall height. So this example will obviously be easy to calculate, but the user can drag the wall in any direction.

So here’s what I thought of doing (but can’t get it right)

- Get start point
- Get a 3rd vector above the start point (Vector3.Up * startpoint)
- Get point perpendicular to the start point and up Point
- Get a point 0.5f units away from the start vector in the direction of the perpendicular point
- Get a point 0.5f units away from the start vector in the negative direction of the perpendicular point.

repeat these steps for end point.

Then I should have the 4 points for the base of my wall.

Anyway here’s my broken code:

```
[System.Serializable]
public class Points
{
public Vector3 startingPoint, endingPoint;
}
public class PerpLines : MonoBehaviour
{
public Points points;
public GameObject positionSphere;
Vector3 upVector;
void Start()
{
upVector = Vector3.up + points.startingPoint;
Instantiate(positionSphere, points.startingPoint, Quaternion.identity);
Instantiate(positionSphere, points.endingPoint, Quaternion.identity);
Instantiate(positionSphere, upVector, Quaternion.identity);
}
public void ShowLines() // method is attached to a button to show lines
{
Debug.DrawLine(points.startingPoint, points.endingPoint, Color.blue, Mathf.Infinity);
Debug.DrawLine(points.startingPoint, upVector, Color.blue, Mathf.Infinity);
Vector3 perpPoint = CalculatePerp(points.startingPoint, points.endingPoint, upVector);
Instantiate(positionSphere, perpPoint, Quaternion.identity);
Debug.DrawLine(points.startingPoint, perpPoint, Color.red, Mathf.Infinity);
Vector3 halfPoint = GetFinalVector(perpPoint, points.startingPoint);
Instantiate(positionSphere, halfPoint, Quaternion.identity);
Debug.DrawLine(points.startingPoint, halfPoint, Color.yellow, Mathf.Infinity);
}
private Vector3 GetFinalVector(Vector3 perpPoint, Vector3 startingPoint)
{
Vector3 heading = startingPoint - perpPoint;
float distance = heading.magnitude;
Vector3 direction = heading / distance;
return direction;
}
private Vector3 CalculatePerp(Vector3 startingPoint, Vector3 endingPoint, Vector3 upVector)
{
Vector3 side1 = endingPoint - startingPoint;
Vector3 side2 = upVector - startingPoint;
Vector3 ret = Vector3.Cross(side1, side2);
return ret;
}
}
```

as you can see my red line isn’t perpendicular to my blue ones and the yellow line should lie on top of the red one but only be 1 unit long.

If anyone has a better idea instead of my whole mathematical vector thing please do share!