- Home /
Get LookAt vector of a tranform
If I want to make on object look at a particular direction, I do
transform.LookAt(theDirection);
How do I retrieve the LookAt direction of the transform?
Edit:How do I retrieve the LookAt position of the transform?
Answer by robertbu · May 09, 2013 at 12:38 PM
A couple of things here. Transform.LookAt() looks at a position in 3D space. It does not look in a specific direction. If you have a direction you want to look you can either do something like:
transform.LookAt(transform.postion + theDirection);
Or you can do:
transform.rotation = Quaternion.LookRotation(theDiretion);
As for the look direction of the transform, LookAt() points positive 'Z' towards the point, so the direction will be 'transform.forward'.
And if I want to get the position the the transform is looking at?
You can't unless you know the distance from the player to the point. For example, if I know the distance to the point is 10.5:
v3Point = transform.position + transform.forward * 10.5;
Note for some things it is good enough to get a possible point. Then just use 'transform.position + transform.forward'.