- Home /
Rotating a plane so that its top is parallel to the camera viewport
I have this code, which creates the plane in front of the camera and rotates the plane to face the camera.
_viewPlane = Instantiate(dialogView2, viewcamera.transform.position + viewcamera.transform.forward, Quaternion.identity) as GameObject;
var dir = viewcamera.transform.position - _viewPlane.transform.position;
_viewPlane.transform.rotation = Quaternion.FromToRotation(Vector3.up, dir);
_dialogViewPlane.transform.rotation.SetLookRotation(dir);
However, the plane is askew such that the top of the plane is not parallel to the viewport.
I've tried a number of different solutions, some of which if I iterated here would REALLY show off my ineptitude on this, but suffice it to say I haven't had any luck. Can anyone help?
Answer by robertbu · Jul 26, 2013 at 09:14 PM
The easiest solution to this problem is to create a vertical plane using the Unity Wiki CreatePlane Script. Then all you have to do is set the two rotations equal:
_viewPlane.transform.rotation = viewcamera.transform.rotation;
if you want to continue to use the built-in plane, you will have to compensate for the default rotation of the plane. Something like:
_viewPlane.transform.rotation = viewcamera.transform.rotation * Quaternion.Euler(90, 180, 0);
Your answer
Follow this Question
Related Questions
Rotation of a camera viewport 0 Answers
Video provided-Rotate 2d character in 3d world 1 Answer
Camera Relative Movement 2 Answers
Camera follows target rotation 3 Answers
Rotate object relative to camera's view 2 Answers