Hi everyone.
I apologize for bothering all of you, but I have an issue I can’t seem to fix without using a Warhammer, and, before wielding it, I would like to have some advice, feedback or general knowledge about my current problem I’m going to describe right now.
I have a scene in wich I render custom homemade billboard. The code for this seem’s all right, as the billboards are correctly facing the main camera.
Here come the tricky part. I now have 2 cameras, using the same viewport (split screen), but the billboard aren’t facing the right direction.
I already made some research on the internet and see that one must add the billboard code in the OnWillRenderObject method. I’ve done as said, without any success.
Any help would be appreciated!
The billboard code, in case it help someone :
if ((Camera.current==null) || (Camera.current.name == "SceneCamera") || (Camera.current.name == "Preview Camera"))
return;
Vector3 posCamera = Camera.current.transform.position;
Vector3 pos = transform.position;
Vector3 right = transform.right;
// First, I determine the plan equation in wich the "up" vector will be projected
float a = right.x;
float b = right.y;
float c = right.z;
float d = -Vector3.Dot(right, pos);
Vector3 B = new Vector3(posCamera.x, posCamera.y, posCamera.z);
Vector3 Np = new Vector3(right.x, right.y, right.z);
// Now, I compute the projection of the camera position to the plan
float k = -((a * B.x) + (b * B.y) + (c * B.z) + d);
float frac = (a * Np.x) + (b * Np.y) + (c * Np.z);
k = k / frac;
Vector3 IntersectionPoint = new Vector3(0, 0, 0);
IntersectionPoint = B + (k * Np);
Vector3 upVector = IntersectionPoint - pos;
upVector.Normalize();
Vector3 newForward = (Vector3.Cross(right, upVector)).normalized;
Quaternion rot = new Quaternion();
rot.SetLookRotation(newForward, upVector);
transform.rotation = rot;