Hello, I want to create a quad at runtime given 2 points (the middle center edges) trying to face the camera at all time.

What I’m trying to achieve is a the flashlight effect, I want to throw a raycast from the flashlight (point A) to whatever object it touches (point B) and then create quad “trying to face” the camera.

A is the starting point of the quad and the middle point of vertices X and Y, and B is the ending point and middle point of vertices Z and V.
I say trying because obviously the quad won’t be able to face the camera like a billboard 100% because of the fixed points A and B, I don’t know what calculations I have to do to get points X, Y, Z and V.

I’m going to give you what I think you want rather than what you specificallly asked for. If it is not right, let me know, and I can revise. Normally with a rotation problem I’ve not solved before, I test it in Unity, but I’m traveling and don’t have access to a computer with Unity at the moment. So to make this work you need to start with a vertical plane one unit on a side with the normals facing backwards. The latest versions of Unity have a Quad on the Game Object menu that will work, or you can use a plane created using the Unity Wiki CreatePlane script with a ‘vertical’ specification. ‘v3A’, and ‘v3B’ are two Vector3s containing your positions A and B from your diagram above:

var direction = v3B - v3A;
var midPoint = v3A + direction * 0.5;
var fromCamera = transform.position - Camera.main.transform.position;
transform.position = midPoint;
transform.localScale = Vector3(direction.magnitude, height, 1);
transform.forward = fromCamera;
transform.rotation = Quaternion.FromToRotation(transform.right, direction) * transform.rotation;

Note you did not specify the height of your Quad, so I just used ‘height’. The code places a Quad at the midpoint between A and B, then it scale it so that it will span from A to B along the local ‘x’ axis, and finally it first rotates it so that it is billboarded to the camera and then does an additional rotation to align the local X (left and right of the plane) with the A to B direction.