- Home /
Look at not working as expected
This should be an easy one, but i can't figure out whats going on. I have a plane that gets created in front of my camera. I use look at in the direction of the camera, but the surface faces up instead of at my camera.
var plane:GameObject=new GameObject.CreatePrimitive(PrimitiveType.Plane);
var fwd=viewingCamera.transform.position+viewingCamera.transform.forward*(viewingCamera.farClipPlane-10);
plane.transform.position=fwd;
plane.transform.LookAt(viewingCamera.transform);
The only thing i can think of is that the edge of the plane is facing the camera, not sure why this would be the case.
Thanks in advance!
Answer by aldonaletto · Mar 07, 2012 at 12:40 PM
LookAt will not work in this case, because it points the forward local direction to the target, but the plane normal is the up local direction. You should rotate the up vector to the camera, like this:
...
plane.transform.position=fwd;
var dir = viewingCamera.transfrom.position - plane.transform.position;
plane.transform.rotation = Quaternion.FromToRotation(Vector3.up, dir);;
Once again you come through with another great answer! Thank you thank you thank you.
Your answer
Follow this Question
Related Questions
Attaching camera to instantiated object 1 Answer
How do you check if Quaternion.Slerp has finished 5 Answers
Changing The Camera Position & Offsetting LookAt 2 Answers
Camera rotate around sphere centre 2 Answers
Camera Aim At Player 1 Answer