# How to use x axis for transform.LookAt

I'm using a skinned mesh with bones in it. I've been trying to make one bone's negative x axis look at another transform, but when I use transform.LookAt, it uses the positive z axis.

How can I change this?

Thanks,

Ariel J

Sorry, I know this is an old thread but I figured I would offer my solution to this problem. You know LookRotation will return a rotation pointing from the front of the object, so you just need to rotate it 90° on the Y axis to get a Quaternion that looks at your target with the X axis. In code it would look like this:

``````Quaternion XLookRotation = Quaternion.LookRotation(dir, transform.up) * Quaternion.Euler(new Vector3(0, 90, 0));
``````

You can of course modify the vector to point any axis or combination of axis towards the target object

You can't. The "forward vector" of any object is when the Z-axis is pointing at it (just like when you're looking at something, you're facing forward). This behavior cannot be changed.

You're probably going to need to do the math manually to rotate the object how you want it, unless you explain your problem more in-depth (perhaps in another question, since it would probably be unrelated).

I have the problem sometimes. What I do is I create an empty game object that is facing in the direction I need it to. Then I make the object that needs to face that way a child of the empty game object and orientated it how I like. Place your code on the Empty Game Object and it will use the Z axis of the empty game object to rotate your object.

Try this!

``````Vector3 target = TargetObj.position;
Vector3 direction = new Vector3(target.x - transform.position.x, target.y - transform.position.y);
transform.right = direction;
``````