- Home /
Question by
bishylewis · Sep 23, 2016 at 10:47 AM ·
frustrum
Framing World Space Canvas
Hi all, I'm trying to find the position / rotation of my camera so I can align it perfectly with a world space canvas.
From other posts: https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html
http://forum.unity3d.com/threads/fit-object-to-screen.36398/
I've written the following code:
Vector3 FrameCanvas()
{
// Calc the size of the canvas
Vector3 bounds = RectTransformUtility.CalculateRelativeRectTransformBounds ( worldSpaceCanvas.transform).size;
float distance = bounds.y * 0.5f / Mathf.Tan (Camera.main.fieldOfView * 0.5f * Mathf.Deg2Rad);
Vector3 targetPosition = worldSpaceCanvas.transform.position + (distance * -m_speech.transform.forward);
return targetPosition;
}
..and it absolutely does not work :-) Can anyone point out where I'm going wrong?
Many Thanks
Comment
Your answer
Follow this Question
Related Questions
How can I know if a gameObject is 'seen' by a particular camera? 11 Answers
Custom frustum culling with scissoring 0 Answers
creating an asymmetric viewing frustum 0 Answers
How do I zoom the camera when it is in danger of colliding or being obstructed 1 Answer
Checking frustrum against Bounds per Object VS Player&List? 1 Answer