x


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!

more ▼

asked Mar 07 '12 at 12:16 PM

hijinxbassist gravatar image

hijinxbassist
2.1k 23 31 38

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);;
more ▼

answered Mar 07 '12 at 12:40 PM

aldonaletto gravatar image

aldonaletto
42.5k 16 43 202

Once again you come through with another great answer! Thank you thank you thank you.

Mar 07 '12 at 11:37 PM hijinxbassist

Exactly the issue I had as well, Thank you!

Jul 19 '12 at 12:21 PM jaycode
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3126
x337
x31

asked: Mar 07 '12 at 12:16 PM

Seen: 699 times

Last Updated: Jul 19 '12 at 12:21 PM