LookAt but without z axis?
Hi,
I want use a tranform.lookat function for look an object but with a different z rotation?
Plz Thank you Sry for my bad english
Answer by duck · Oct 12, 2010 at 09:15 AM
There's no version of LookAt which operates on a different axis.
To get around this, you can either:
a) rotate the object after performing the LookAt, like so:
transform.LookAt( target );
transform.Rotate( -90, 0, 0 );
or,
b) make your visible object the child of a "dummy" empty game object, and rotate the child object by 90 degrees in the desired direction. Then perform the LookAt function on the empty parent game object.
hope this helps!
Answer by Max Kaufmann · Nov 04, 2010 at 07:21 AM
Z-Rotation, globally, determines the "up" direction (twisting around the line-of-sight axis). So, easy, just pass in the current up vector as the optional second argument:
transform.LookAt(target, transform.up);
Thank you! What worked for me is using another objects transform with the transform.up so I could use it's axis without needing to be a child object.
Worked like a charm, just put my camera up and text lined up horizontally
Answer by Pixeye · Jan 29, 2011 at 07:25 AM
I assume you're making 2d game?
You can use something like that
var targetPoint: GameObject // gameobject to look to
function Update()
{
transform.LookAt(targetPoint);
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0); // lock x and z axis to zero
}
Try using transform.eulerAngles . With that you can also lock your Z axis to other different degree. For example :
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 75);
Answer by Twayne · Nov 02, 2010 at 08:30 AM
If you mean you want the LookAt feature but leave z fixed say z = fixedZ, I was able to do this with
transform.LookAt(Vector3(target.position.x , target.position.y , fixedZ));
or if you want the z to stay level with the transform
transform.LookAt(Vector3(target.position.x , target.position.y , transform.position.z));
Your answer

Follow this Question
Related Questions
How to make the front, left, right, or the back of a gameobject look at a target? 1 Answer
enemy look at GameObject player? unity ver. 5.2 C# 0 Answers
How do i make my enemy look at player on only one axis? 1 Answer
Shader Graph: Rotate texture to look at 'camera' 1 Answer
Help for Realistic car Chase/Pursuit 1 Answer