- Home /
Transform.LookAt - wrong vector
Hi,
i ve created a gameobject with a simple plane. The material is a transparent/vertexlit and i gave it simple 2d-grafic as the base-texture. Now ive added the following script/code.
private void Update(){
transform.LookAt(Camera.main.transform);
}
If i run the gamemode, the texture always has the wrong rotations, so ive never see it. All these gameobjects should everytime directly face up to my orbit-camera. Unfortunately ive too few knowledge about vector-math, so therefore it would be great to get some hints on that..
thanks a lot,
Answer by Random Indie · Jun 03, 2010 at 12:21 AM
Might be that the plane doesn't have the forward direction you're thinking it does. If I remember correctly the lookat function uses the forward vector which I think is the positive z axis for the game object (might be x but IIRC I think x is 'right').
So depending on how you set up the plane it might be looking in the right place, but on it's side so you only see the edge and therefor might not actually 'see' it.
If that's the case you can either fix the plane's rotation in max/blender/what have you, or you can stick it it in an empty gameobject and orient it properly as a child then stick the rotation code on the parent gameobject.
Hope that helps, if you need clarification on anything let me know.
Cheers
Thanks to all for there quick help. It helps to create a extra gameobject and rotate the plane-go inside of it.Thanks
Answer by Mike 3 · Jun 02, 2010 at 04:06 PM
Try using transform.rotation = Camera.main.transform.rotation
Sprites and Planes are very often made so that they face the camera when oriented the same way
Answer by Tetrad · Jun 02, 2010 at 04:19 PM
Try comparing what you're doing to this script:
http://www.unifycommunity.com/wiki/index.php?title=CameraFacingBillboard
Answer by Peter G · Jun 02, 2010 at 05:59 PM
Not sure if you created your own plane or not, but if you did, you might have assigned the vertices in the wrong order. Try reversing the direction you assign the points in i.e. clockwise instead of counter-clockwise or vice-versa.